Exploring cocos2d-javascript for my next game

My previous game endeavor, fusion, is nearing the end of its development life. While there are many things I'd like to do with it, I have to remember why I started it in the first place - to learn JavaScript game development. I have wanted to make video games since I was very young, but have had trouble getting started on a project until Fusion. It is by far the most complete game I have ever made.

With that said, it is also sluggish, buggy and hard to maintain because I did not use a framework while developing it. That was a very conscious decision on my part, because I wanted to understand what was happening at a low level and was concerned that a framework would hide certain things from me that I wanted to know about.

Now that the game has nearly reached the "final" product, I can begin to look to the future. Again, I am collaborating with George Emond on the next project with him providing all artwork and I will be doing all of the code. We are in the early stages of discussing a project, but I have begun looking for frameworks to build this on.

While looking for a framework, I came across cocos2d-javascript. This is a JavaScript implementation of a framework originally developed in Python but currently most widely used on iOS. I have been using cocos2d-javascript v0.1.1 for a few days now and thus far I like what I see. I followed the tutorial to make a breakout clone, and am continuing where it leaves off to create the full game. You can see the current progress at my github repository.

As I move into cocos2d-javascript, I can appreciate many of the things the library does that were tedious or non-obvious to me while working on Fusion. As a few examples:

  • The concept of scenes and layers, obvious to me now, was not something I even thought about while writing Fusion. The entire game was a single scene with a single layer. This caused issues with going between the game and the store, and prevented me from ever creating any kind of main menu. cocos2d-javascript implements this concept and it should help me switch between distinct sections of the game.
  • Events and event listeners are a great tool for de-coupling certain sections of the code that only loosely relate to one another. For instance, in my breakout clone I have an event being fired when a brick is destroyed. This event is listened to by the HUD layer, which increases the score upon the brick's destruction. Prior to implementing these events, the ball object was awkwardly navigating through the node tree to find the HUD and increment the score.
  • The CommonJS spec for including files is very modular and helps keep my files free of clutter and unnecessary namespacing. When I first used this with node.js while working on wsilent, I found it confusing and felt like I spent more time managing scope than writing code. But as I got past those hurdles and began to utilize it for code separation, I began to like it. Seeing it used natively within cocos2d-javascript is a good thing for me.

My experience with cocos2d-javascript is still fairly minimal. Once I finish this breakout clone, I will move onto the actual game that George and I are building. At this point, we know it will be an isometric action game. Beyond that, we have not fleshed out details. But this gives me a starting point to learn how to set up a game like this.

As an added bonus, cocos2d-javascript is a good transition into Python, where the library was first written. My next game may leave the web entirely and become a standard application. But I won't think about that too much for now, since I want to take this one step at a time.


Wonderful post, it is a breath of fresh air to at last find educational information on the internet, I am genuinely grateful to encounter a blog that is not full of the usual garbage, bless you.

<p>Trackback from <a href="http://www.gobay.ru/product.php?id_product=1021048">http://www.gobay.ru/product.php?id_product=1021048</a>.</p><p>Exploring cocos2d-javascript for my next game | Steve Phillips</p>