Today I'm going to start with using snowblower to make some request animation frame loops.
In whatever context you want, make a SnowBlower factory for a stage. Your runtime should create one instance of a stage for every canvas you need.
Here it is folks. I did not write specific code for your rendering engine. You need to expose whatever stage to the objects your are creating so they can call this code:
Piece of cake. Now all you have to do is pick a rendering engine, render the view in the request animation loop, and create your game.
I suggest using PIXI.js or phaser.js because it's a really great API for canvas rendering. Make sure you do all the work before adding the item to the stage. Remove as many variable declarations outside of the draw function as possible to prevent as much resource allocation and memory leaking as possible. Keep it simple. If you want to pass the draw function a parameter or use "this" as the stage, you can modify your request animation loop like this:
In the end, everything is logical and fun.
Have any suggestions? Feel free to comment/post on Google Plus.
Thanks!
~function(){'use awesome';console.log('josh')}();
Learn how to code native javascript and discuss the merits and problems with using monolithic libraries.
Friday, February 28, 2014
Monday, February 24, 2014
SnowBlower and Object Composition
I'm going to talk about this "library" and why it's very useful. It takes a lot of the compositional techniques of objects and makes it really fun.
Here's an example of how to use SnowBlower.
It takes all the functions and objects that you pass to it, and either executes it in the context of your new object, or mixes it into your new object. If you need polyfills for your environment, just define
Array.prototype.reduce, Object.create, and replace the Object.prototype.hasOwnProperty function to reflect your environment.It's designed to be small and SnowBlower assumes you have all the pieces and closures that define your object up front. If you need to compose factories, you can just create a function that does it for you.
This is a DRY method of reusing functions you have already defined to compose objects. The sky is the limit! Just thought I would share this compositional technique with you.
~function(){console.log('josh')}();
Wednesday, February 19, 2014
Your Instatouch Library is Cute
I love the JS community. In fact, I think it's the best community to be in programming wise. There is so much support when you need help, especially if you have no idea what you are talking about.
I just want to point out a few things that have taken steps backwards in the past few years when it comes to mobile web experience.
There are at least a dozen different libraries like this: https://github.com/ftlabs/fastclick where the goal is to make the web more responsive. As a mobile phone user, these packages make my experience WORSE. There, I said it.
The reason why it's worse, I've found, is because I like to scroll and read content on the page. If my finger happens to press a link while I am swiping on the page, it fires the click event! This is definitely not good if that link happens to do something very permanent. At best, I found myself pressing the back button so much I gave up completely frustrated with my experience.
My recent experience on cheezburger was rather frustrating because the links take up the whole screen! Maybe I'm just too slow, or JS wasn't designed to do this. I'm willing to accept either, but I'm definitely used to the way browsers work on my phone.
Your Instatouch library is cute, but it makes my user experience more difficult in some cases, and only marginally faster in others. Thanks but no thanks guys, I'll take the DOM as it is.
-Josh
I just want to point out a few things that have taken steps backwards in the past few years when it comes to mobile web experience.
There are at least a dozen different libraries like this: https://github.com/ftlabs/fastclick where the goal is to make the web more responsive. As a mobile phone user, these packages make my experience WORSE. There, I said it.
The reason why it's worse, I've found, is because I like to scroll and read content on the page. If my finger happens to press a link while I am swiping on the page, it fires the click event! This is definitely not good if that link happens to do something very permanent. At best, I found myself pressing the back button so much I gave up completely frustrated with my experience.
My recent experience on cheezburger was rather frustrating because the links take up the whole screen! Maybe I'm just too slow, or JS wasn't designed to do this. I'm willing to accept either, but I'm definitely used to the way browsers work on my phone.
Your Instatouch library is cute, but it makes my user experience more difficult in some cases, and only marginally faster in others. Thanks but no thanks guys, I'll take the DOM as it is.
-Josh
Tuesday, February 18, 2014
Installing Node.js on my Android Phone
I have the LG Optimus G on Sprint (LS970) and had to do a couple of things to my phone before I could start using node from the command line. I had to root, install TWRP, and then install DebianKit (the biggest offender on being a Pain In my Rear.)
Anyway, here is the steps I took to get everything working.
Some notes I had:
In functional health:
~function(){console.log('Josh')}()
Anyway, here is the steps I took to get everything working.
Some notes I had:
- I could not install anything useful on my phone using apt-get until I resized the debian.img file on the sdcard.
- I had to do a lot of trial and error before I could finally get the debian image resized correctly
- Installing nvm was easy once I had space
- I had fun
In functional health:
~function(){console.log('Josh')}()
Monday, January 13, 2014
Yet Another Gulp.js Post - Compositional Gulp
Gulp is the new build tool and I highly recommend that you use it over grunt for building things. I found that it's nice to do something like this (taken straight from the repo example):
I mean look at it, it's really clean, except for the anonymous callback pattern.
Yet maybe I'm missing something here. Take a look at the following snippet:
Take a minute and think about it. This enables you to make command line tools that do whatever you want!
Even better, what if you used a functional composition library like... say...
So this is really cool, and make your own judgements, but you can do some interesting things with it. For example, remember that
That was fun! Sure it may not be the best way to build your gulp tasks, but surely this allows for mix and match DRY task factories.
Are you going to use it? I'd say get back to writing fun code ;).
In functional health,
"Josh"
P.S. Don't forget about
Edit:
This example shows the sheer power of symphony which give you DRY tasks given a good configuration. Watch out though, because
I mean look at it, it's really clean, except for the anonymous callback pattern.
Yet maybe I'm missing something here. Take a look at the following snippet:
Take a minute and think about it. This enables you to make command line tools that do whatever you want!
Even better, what if you used a functional composition library like... say...
Composer.js?So this is really cool, and make your own judgements, but you can do some interesting things with it. For example, remember that
this is the object that composer is making, right? See the following.That was fun! Sure it may not be the best way to build your gulp tasks, but surely this allows for mix and match DRY task factories.
Are you going to use it? I'd say get back to writing fun code ;).
In functional health,
~function(){console.log(this)}.call("Josh");"Josh"
P.S. Don't forget about
Composer.symphonyEdit:
This example shows the sheer power of symphony which give you DRY tasks given a good configuration. Watch out though, because
this is a Object.created version of gulp.
Labels:
api,
architecture,
composer,
Composer.js,
factory,
gulp,
Inheritance
Sunday, January 5, 2014
That's a Novel Script
I revisited my old library NovelScript.js and realized how bad it was. No wonder nobody wanted to use it. It was insanely opinionated and had a terrible plugin system. I set out to fix these things a few days ago, and here's what I came up with.
(Note: I'm not necessarily advertising NovelScript more than I am sharing my design philosophy.)
I wanted something to give my Visual Novel a backbone, so I made a list of things I would need to create it myself:
I grabbed a small event engine and learned how it worked, then redesigned it to contain "Default" events that ran after the event stack ran. For instance: if I trigger "page:draw", I would want the function that actually draws the page to be the "default" one instead of one the other events on the stack. Setup events should not actually draw on the canvas.
I wanted a way to expose the DOM api and use mixins to define image elements inside of the options config. A simple JSON Config looks like this:
On top of this, I added the ability to load images on demand, and an event that fires when all images are done loading.
Those options match up to the dom api, including the styles. When using the default draw functions, it will actually calculate the width/height of the image using the dom api if those values aren't specified.
Changing the way every NovelScript object works is as simple as adding a closure using Composer.js.
I also wanted to add some play/stop/pause functions to handle my audio.
All in all, I took a really holistic approach and made the API have a really conventional opinion on how to do things. I hope this helps you make your Visual Novel work well! Remember that no matter what you want to do on the web, you still are coding in Javascript, and you should work with what you have.
Good luck!
~function(){console.log("Josh");}();
(Note: I'm not necessarily advertising NovelScript more than I am sharing my design philosophy.)
I wanted something to give my Visual Novel a backbone, so I made a list of things I would need to create it myself:
- An event engine that gave me a bit more control than the native one
- I need some standard events
- Some standard way to load images, sounds, and music
- A good way to expose the DOM to me to make it feel more like an HTML app
- A really good mixin/plugin engine that enclosed functionality using functions
- A couple standard draw functions
- Abstracted audio functions
What I did instead
I made sure that I wasn't reliant on anything except Composer.js which became the plugin engine. It allows the developer to extend NovelScript in a very meaningful way that didn't impede on the developer.Events
I grabbed a small event engine and learned how it worked, then redesigned it to contain "Default" events that ran after the event stack ran. For instance: if I trigger "page:draw", I would want the function that actually draws the page to be the "default" one instead of one the other events on the stack. Setup events should not actually draw on the canvas.
Images
I wanted a way to expose the DOM api and use mixins to define image elements inside of the options config. A simple JSON Config looks like this:
On top of this, I added the ability to load images on demand, and an event that fires when all images are done loading.
Those options match up to the dom api, including the styles. When using the default draw functions, it will actually calculate the width/height of the image using the dom api if those values aren't specified.
Extending NovelScript? Hell yes.
Changing the way every NovelScript object works is as simple as adding a closure using Composer.js.
I also wanted to add some play/stop/pause functions to handle my audio.
All in all, I took a really holistic approach and made the API have a really conventional opinion on how to do things. I hope this helps you make your Visual Novel work well! Remember that no matter what you want to do on the web, you still are coding in Javascript, and you should work with what you have.
Good luck!
~function(){console.log("Josh");}();
posted from Bloggeroid
Labels:
api,
audio,
canvas,
composer,
design,
events,
html5,
images,
javascript,
novelscript
Friday, January 3, 2014
Best Practices Can Change
Spend some time today learning the concepts behind technology coupling shown in this video:
If you'd like you can spend your time complaining about definitions on coupling, or you can accept your new JSX overlords. Or maybe you should just accept that maybe your practices aren't best.
For a long time I was victim of this myself, where I found myself writing the same code over and over again, just for the sake of consistency in my C# code. I always had the same business logic functions, calling the same functions on a separate class, yet getting similar results repeatedly, and coupling myself into a corner. I didn't see it at the time, but I was making a total mess of my code!
I found myself trying to implement interfaces on objects I designed on only two classes, with the intention of calling it just once. I found myself having to maintain my object definitions in (I counted it) 25 different places when I had to add a column on the SQL table. Sure, the procedures and parameters changed my definitions, and that part was good, but for the sake of consistency, I wrote all the lines over and over again.
This practice was the worst decision of my life.
I almost wished I could use LINQ to generate an array in a few lines of code instead of a ridiculous cluster of declarative parameters. (So I did, but that's totally beside the point.)
I actually decided enough was enough about 2 months ago when I started working on some generic Object Extension components. I was going to make C# do the overhead for me instead of relying on declarative stuff. Here are some of the reasons why:
You know what happened to my code?
It shrunk in half. This code is much more maintainable, because I expressed it in terms of static functions instead of classes, objects, and data types. I practically ignored them (With the exception of the Nullable classes, I really like those.)
Here are some of the methods I implemented that now extend my objects:
I've yet to work out casting a sql data row to a reflective data record, but there will be a time when I will call something like this...
...and I won't regret it. I won't regret it a single bit.
This kind of technology makes
In the end, I maintain my Business Objects in 2 places. Once on the database server, and once on the front end (or multiple times if I seperate out an Insert/Update object that functions differently with the same property signature.) The best part is that I can simply populate whatever object I want with my data results implicitly, with one line of code, in a repeatable fashion, and have it work in every environment as a side dll that I can include in my project.
If you feel disgusted, mad, or think this is bad, you better have a really good reason why, because I haven't found a reason (except for maybe dealing with processor performance on a computationally expensive algorithm.) If you are using C# for something besides rendering a template and gathering your data, this clearly doesn't help you anyway. I like saving my company time and money, and it almost seems like a no brainer when dealing with a childish argument like: "Everyone is doing it."
That sounds like a drug deal to me.
~function(){console.log("Josh");}();
If you'd like you can spend your time complaining about definitions on coupling, or you can accept your new JSX overlords. Or maybe you should just accept that maybe your practices aren't best.
So many feels
For a long time I was victim of this myself, where I found myself writing the same code over and over again, just for the sake of consistency in my C# code. I always had the same business logic functions, calling the same functions on a separate class, yet getting similar results repeatedly, and coupling myself into a corner. I didn't see it at the time, but I was making a total mess of my code!
I found myself trying to implement interfaces on objects I designed on only two classes, with the intention of calling it just once. I found myself having to maintain my object definitions in (I counted it) 25 different places when I had to add a column on the SQL table. Sure, the procedures and parameters changed my definitions, and that part was good, but for the sake of consistency, I wrote all the lines over and over again.
This practice was the worst decision of my life.
What a total waste of my time!
I almost wished I could use LINQ to generate an array in a few lines of code instead of a ridiculous cluster of declarative parameters. (So I did, but that's totally beside the point.)
Making a Change Toward Maintainability and Fun
I actually decided enough was enough about 2 months ago when I started working on some generic Object Extension components. I was going to make C# do the overhead for me instead of relying on declarative stuff. Here are some of the reasons why:
- My front end performance was based on form loading time and not submitting time, because my organization doesn't need realtime processing, they needed data entry
- My code base was the size of a continent and I'm the only maintainer
- Some of the things I wanted could simply Extend Object using Object Extension (More on this later)
- I don't care about your feelings
- Using a procedure to grab SQL Parameters dynamically
- Using Object Method Extension to perform:
- Reflection operations
- Dynamic Column evaluation
- Dynamic Object population
- Creating ASP.NET MVC Web forms insanely fast using reflection
- Make functional components, not structural components
You're kidding right?
You know what happened to my code?
It shrunk in half. This code is much more maintainable, because I expressed it in terms of static functions instead of classes, objects, and data types. I practically ignored them (With the exception of the Nullable classes, I really like those.)
Here are some of the methods I implemented that now extend my objects:
- Object.get(String PropertyName) (Returns Object.PropertyName if it exists)
- Object.set(String PropertyName, Value) (returns Object and chains)
- Object.propertyExists(String PropertyName) (returns Boolean)
- new ReflectiveRecord(DbDataRecord myRecord) (returns an encapsulated DbDataRecord that does the following...)
- ReflectiveRecord.populate(Object myObject) (Applies a convention that the Object you are populating has the Same Property Names/Column Names)
- DataAccess.InsertDatabase(String ProcedureName, ParametersObject) (Grabs procedure definition from database and dynamically pulls values out of ParametersObject)
I've yet to work out casting a sql data row to a reflective data record, but there will be a time when I will call something like this...
...and I won't regret it. I won't regret it a single bit.
This kind of technology makes
SELECT * FROM TABLE inside of a stored procedure actually look pretty appealing, instead of selecting a bunch of columns in an unmaintainable fashion.In the end, I maintain my Business Objects in 2 places. Once on the database server, and once on the front end (or multiple times if I seperate out an Insert/Update object that functions differently with the same property signature.) The best part is that I can simply populate whatever object I want with my data results implicitly, with one line of code, in a repeatable fashion, and have it work in every environment as a side dll that I can include in my project.
Go home Classical Structure, you're drunk!
If you feel disgusted, mad, or think this is bad, you better have a really good reason why, because I haven't found a reason (except for maybe dealing with processor performance on a computationally expensive algorithm.) If you are using C# for something besides rendering a template and gathering your data, this clearly doesn't help you anyway. I like saving my company time and money, and it almost seems like a no brainer when dealing with a childish argument like: "Everyone is doing it."
That sounds like a drug deal to me.
~function(){console.log("Josh");}();
posted from Bloggeroid
Subscribe to:
Posts (Atom)