Heli Merc: Scrolling, shooting and missing functionality E-mail
Saturday, 27 November 2010 20:04

Over the last day or so, I got stuck into setting up a weapons class so the helicopter can shoot and a sprite class to animate explosions. To keep the frame rate high, I've decided to create a pool of weapon and explosion objects, then, when a weapon is fired, or something blows up, a message is sent to the relevant AIModel which will then search through the pool for an inactive object, and if found, then display it on screen. Once the object has finished it's task, it is then released back into the pool so that it can be re-used.

In order to achieve this for a phone application with limited resources, the best way is to create two AIModels, one for all sprites and one for all the weapons, rather than create an AIModel for each weapon and sprite. These two AIModels hold tables of properties belonging to all the objects that have been created.

Once I had the weapons in, I decided that I wanted to to make them a bit more obvious by making them "flash". This is achieved in much the same way as it would have been back in the colour-cycling days of the Amiga and it's ancestors.

To get the flashing effect, the weapon are made up of polygons that are textured. After each frame is drawn, the texture map's UV offset is moved so that on the next frame the weapon will be drawn in a different shade of the same colour. I've set up four colour cycles, a blue, a red, a green and a grey to use for different purposes.

The next step was to create a sprite AI Model, which turned out to be even easier, since it was largely a copy of the weapons AI Model, minus some weapon specific properties, with a few animation properties added. Of course, I needed an explosion, which I was able to aquire from Phaedy's in-browser explosion generator. I then wrote a quick bash script to take 8 of the explosion images, scale them down to a smaller size and assemble them into a single image. The explosion model in Shiva3D is simply a Billboard, for which I change the texture map's UV offset in much the same way as I did to make the weapons flash.

After this was done, I tacked on a button to shoot that would allocate a weapon object of type missile. The missile will then fly under it's own control for a fixed number of game units, at which point it would spawn an explosion sprite and return itself to the weapons pool. Once the explosion had completed it's 8 frame animation, it would return itself to the sprite pool.

It was nearly the end of the day, so I the last thing to do was to add some post rendering bloom effect to give the sun in the background a bit of a glow and make it look less like it's simply been drawn onto the sky.

Missing Android functionality

By and large, Shiva3D's support for Android devices is pretty good. The version of OpenGL that runs on phones is called OpenGL ES, and it doesn't have the same level of functionality as the full version of OpenGL that is available on your typical desktop machine. With this in mind, it's not surprising that some features might not be implemented.

The last thing I did today was play around with the bloom effect, which I later discovered wasn't supported. In order to work around this, I took a snapshot of the bloom effect in the virtual machine and examined it closely in Gimp. It wasn't too hard to come up with a similar effect by putting a white disc on top of a transparent, blurry yellow disk, which was then imported into Shiva3D as a texture and assigned to a billboard that I position in the sky. The end result is quite similar to the bloom effect, at least on the sun.

A couple of days ago I tried setting up a nice sky gradient as a background image and I found out that this wasn't supported on Android.

A simple workaround is to add a billboard that fills the screen, texture it with the background image and then parent it to the camera.

After I did this, I found out about another limitation of phone hardware, the screen isn't always true colour, it's actually 16 bit on many smart phones, especially ones with LED screens. The nice gradient that I created turned into a horrible banded mess.

In the end I gave up on the idea of a background image, and instead I'll be using a flat colour so there's no banding.

The picture to the right shows the what the gradient should look like (before), and what it ends up looking like on the phone (after).

This also brings up another point. If you are working on a phone game, keep in mind that the texture bandwidth is limited. On a phone like the Desire, with a 800x480 pixel screen, if you were to draw a nice background image that was 800x480 pixels, you'd use up almost half your available texture bandwidth. If all the unique textures in a frame exceed a total of 1024x1024 pixels, then the frame rate will be fall.

Try out the latest version discussed in this blog post!

Return to the Heli Merc section!

blog comments powered by Disqus