Feb 11, 2010


I've been working recently with a jQuery plugin called gameQuery, which is a basic 2D game development library for Javascript. It is designed to help you make simple browser games without the use of Flash or Java - which is nice, since Flash development doesn't work so well in Ubuntu (Adobe does provide an ActionScript compiler for Linux, but it doesn't really have any tools with it) and Javascript is a lot easier to program in than Java.

Right now it is still very basic, however it handles certain primitives for you quite well. Animations are implemented for you using tiled images (this is where you put all your frames into a row/column in a single image) which is very handy and much better than using animated .gifs. It will also do the preloading for those animations so that they don't need to be done during the gameplay. There are also mechanisms for grouping different animations into layers so that you can have different background/foreground groups, sprite groups, etc.
There's also some nice little addons for the game loop and input handling.

Other than that, there isn't really much to it. It has sound, although it is experimental and is not guaranteed to work (I haven't tested that part out yet). Supposedly it has collision detection, but it doesn't seem to work for me. Maybe I'll fix it and submit a patch.

I've been expanding on it a lot, I've made up two view classes that handle a scrolling background. You can either just straight up scroll by calling scroll(dx, dy), or you can have a "locked view" where it follows a particular sprite (it nicely handles the edge of the screen!).
I've also built-in a more efficient object management system using quad-trees, which are a space-partitioning data structure. It means that when you do location-dependent things like collision-detection you don't need to query every single object in the game, you just need to update the visible ones. This might also be good for animation rendering since you wouldn't need to update animations that are not visible.

Anyway give it a shot if you like, but remember that it is still pretty alpha! And don't bother with IE since it is really too slow for something like games.


derjan said...

What do you mean with

... Javascript is a lot easier to program in than Java:

If you mean, that JavaScript runs natively in a Browser, while Java requires a plugin, you can use GWT to solve this.
If you mean, JavaScript is an easier language, you should think about the differences.

Java is static typed, it has a clear object oriented focus with classes and namespaces.

So I would say, that JavaScript - as a scripting language - is great for doing some small things, while a big application like a game should be developed with a language like Java.

Rob Britton said...

Sorry about that, I suppose my comment was a bit ambiguous. What I meant was that it takes less effort develop something using Javascript than it does with Java.

I used to believe the same thing as you, for the first 7-8 years of my life as a programmer I used C++ and Java and believed that without type-safety the rivers would run with blood and Nazis would come back to life riding dinosaurs, or some other apocalyptic scenario like that. Then I actually learned how to properly use dynamically typed languages like Javascript, Python, Ruby, etc. and started thinking that maybe the type-safety thing is not all that it is cracked up to be. If you can point out some data (note that the plural of anecdote is not data) I'd love to see it, but until then an argument about static vs. dynamic typing is completely pointless.

Blues said...

@derjan: I'd have to agree with Rob. Javascript is a fully featured lisp/scheme like language. It has lambda functionality and prototypal inheritance rather than classical making it truly object-oriented. An object may extend another object.

Javascript does in fact have far more functionality than Java. That said, there is also a lot of crap in Javascript mainly because of its history as the weapon of choice in the browser wars. However, the fact that it is so much easier to start with Javascript, and see results immediately without a compile step in between means that there is a large developer base, and many of them spend a lot of time experimenting with the language (eg: John Resig, Dean Edwards, Thomas Fuchs, Nicholas Zakas, Dav Glass).

Javascript, despite its name, isn't a scripting language. It's a fully featured language that runs everywhere. Check out node.js, for example.