Javascript game engines

Past half year or so i have been reading a lot about javascript game programming, as you know in software/tech world time goes fast, so there is no surprise when a new or updated software or some sort of hi-tech product pops out quite quick, that leads to my main theme of this post.

what happens when browsers get fast, when they evolve, and mobile devices with integrated smart OSes lies in peoples pockets? you guest right, products/applications are born,  and not some simple programs, but games. To create a game takes lot of effort, developers need to know math's good, especially trigonometry, to know sin, cosine, tangent other functions, and the designers need to create the game worlds art(pixels, map layout, models..), and don't forget the writers that make fun and engaging story for your game, not talking about management that brings it all together. Well my point is made lets look at what makes javascript web game programming easier.

On what you are about to read  is just my opinion after trying develop or studying the fallowing:

GMP Javascript Game Engine - is a fast, free, javascript game engine, dual licenced under GPLv2 and MIT licenses. It’s small, simple, and easy to learn and use.

  • A ready-to-go, self-booting game loop
  • Easy-to-use mouse and keyboard input managers
  • Robust classes for organizing your game code and making all your game widgets and sprites
  • Complete API documentation, and a user manual with tutorials
  • Plugins to help with game development (coming soon)
  • Templates for game components and even entire games (coming soon)

Personally i liked this one the most of all the javascript game engines i tried, though it doesn't support some functionalities that other engines do, but its very nicely programed, runs fast and has good documentation.

Akihabara - is composed of a number of libraries that use HTML5 canvas tag and some standard hooks.

  • Gamebox module is complete and compact enough for making games.
  • Gamecycle module provides a complete generic game cycle.
  • Toys module provides lots lots of common routines during the game developing.
  • Help module provides some Javascript-specific functions, such object copying, randomizing functions, string/array handlers and the  akihabara function, that automatically sets a comfortable preset of configuration.
  • Tool module provides simple developing tools.
  • Trigo module provides some math stuff for moving objects in a direction or following a round path.

This one is really powerful, if you want to create something complex, that supports sounds, has tools for easier mobile programming, then this game engine is for you, the big minuses are that this project is quite young still lacks documentation and the code is bit a mess, but all in all it comes second in my engine choice.

Thats it these are my top choices if i would develop a game in javascript i would chose one of them, here are some links to other mention worth engines:

gameQuery - gameQuery is a jQuery plug-in to help make javascript game development easier by adding some simple game-related classes. It's still in an early stage of development and may change a lot in future versions.

Render Engine - The Render Engine is a cross-browser, open source game engine written entirely in JavaScript. Designed from the ground up to be extremely flexible, it boasts an extensive API and uses the newest features of today's modern browsers.

And here are some javascript games:

Javascript quirks and scope

Though i like to think that i am quite adept at javascript understanding sometimes i forget the quirks it has.
Just today i was programming and wanted to call a simple function editPost, then when testing what i wrote i get an error saying "editPost is not function", damn i said to myself thinking that i mistyped somewhere, but as it turned out i used editPost as a global variable in another function, there i forgot to add the 'var' and it became global. I think its a common mistake and sometimes its hard to maintain such code especially when working on bigger projects witch has lots of javascript lines. Sure there are methods to solve scope problems like namespacing, using OOP programming style in general, but you must apply these methods early in development in order to escape the mess later. Here's a simple example of my problem that i had:

function getPost(){
    editPost = 'not used';  //no 'var' means the variable is global scope; this type of variable is called implied global
    ...
    return post;
}

function editPost(id){
    ...
    //browser will shout an error, that "editPost is not a function
    ...
}

There is a good book about these kind of quirks that Javascript has i recommend you reading it if you are interested, its called "JavaScript: The Good Parts" written by Douglas Crockford. It's a small book, but informative and explains javascripts buggy parts like:

'' == '0'          // false
0 == ''            // true
0 == '0'           // true

false == 'false'   // false
false == '0'       // true

false == undefined // false
false == null      // false
null == undefined  // true

' \t\r\n ' == 0    // true

and many other awful and beautiful features of javascript insight-fully.