Finally it’s time to show some progress with a new tech demo. This demonstrates the integration of physics into the Jetpack game engine, along with some live-cached graphical effects and Thing grouping (the moving platform). Note this is just a test of the physics engine and does not reflect what the final game will look like. Please report any problems you experience, and if you like the progress, please digg this post!
Earlier in the project I put some time into writing my own physics engine, but I decided to try a 3rd party library for physics and I’ve been very happy with the result. I am reluctant to use 3rd party code because when I’ve tried in the past I spend more time working around limitations, bugs, and poor documentation, than if I had simply written it myself. But in this case, using the 3rd party physics engine box2dflash has turned out to be excellent. The API was much better than I expected, the docs have some quirks but are substantial, and the community is large. The result is way more functionality than I would have ever achieved, with a lot less work on my end.
While doing some minor optimization checks by selectively disabling certain features, I noticed a significant slowdown was being caused by alpha changes (translucency). Strangely, if the graphic contains translucency but you don’t alter the alpha, there is no slowdown. So I implemented a smart per-object cacheing system – in this case, alpha is applied and the graphic is drawn to a cache, and future changes in alpha trigger a cache refresh. This is useful for any property that doesn’t change too often, like a rotated object at rest – render the rotated version to the cache, then all future frames will render the cache without rotation. Using this technique and the box2dflash physics engine, on a typical machine I’m able to get 100 balls interacting (each with 2 translucent graphical objects), plus all the level blocks, and maintain an average 40fps. Using Flash as a platform will not be a problem.
The next tech demo will be a control test – binding user input to commands, passing those commands to a Thing’s state machine, applying forces/motion based on the current states, and activating graphical representations of those states. In other words, running around. To be updated on future Jetpack developments, please register on JetpackHQ!
This is a little jerky at times mainly because the code that lowers the frame rate under high load isn’t currently functional. It’s trying to hog the processor and the browser isn’t having it. This will be fixed in a later release.