Wednesday, October 2, 2013

September Game "Maze of the Rat King" bug fixed, time to start on October game

So, if you've been waiting to play the September game until I'm done with it, I now give you permission to hit http://bigdicegames.com/RatMaze/maze.html as I'm not going to be updating it further.

That sounds bad, let me rephrase: "Yay, the maze game is now full up with awesome, and it's ready to go!" Which sounds a little over the top. Somewhere in the middle, though, I'll say, yes, there's stuff that didn't get done (like any of these fixed time limit games), there's stuff I'm pleased with, and I'm happy to have working pieces to carry forward to the next game.

The last bit that I just fixed was a weird loading behavior - when I would load the game the first time, or one of my friends would load the game any time, certain assets wouldn't load, and the game would just show a black screen.

Turns out, what was happening was that I had a bug where I was launching the Jaws.js game framework twice. Jaws, like most Javascript engines, gets a lot of its work done through callbacks, so what was happening was that I'd set up a list of assets, the framework would issue asynchronous calls to load those assets, and would go away. Each time an asset would be loaded, it'd tally up the loaded asset (or failed load, if that happened, which it didn't in this case).

I was loading 23 assets, I was seeing 23 callbacks, but I was only seeing 20 loaded assets. It took me a while to recognize that 3 of those assets were being loaded twice, and it took me a while to recognize that I was launching the framework (and hence the loader) twice. Once I saw that, it made sense - the tile art was much smaller than the splash screen, and loading a 100x115 PNG twice is much faster than loading a 800x450 PNG, so some of the tiles would get loaded twice, the loader would say, aha, I've loaded 23 things, that's all I need, let's start the game. And then my splash screen code would leap into action and it'd all end in tears, as the first thing that I do is try to draw my biggest piece of art. Bam.

I'm not going to badmouth Jaws.js - it's so far been a pretty good tool, and I've been able to walk through the code pretty well. There are things that I'd change, and a few places where I've stitched in debugging code and a few places where I've stitched in new functionality. I really need to get back to the original author and share my experiences - even if he's not interested in my patches, I expect he'd appreciate knowing that it's getting use.

I do think that as I continue to make games with my toolbox of code, I'll lean less and less on Jaws.js and might eventually get rid of it altogether. I think right now, I'm using the asset loading and the keyboard/mouse/touch handling, which I could probably rewrite without much effort if I needed to.

I don't need to for the moment, so I won't.

Next up: Our hero has escaped from The Maze of the Rat King, and pursues him overland through adventures in the wilderness.

No comments:

Post a Comment