Archive for the ‘Mobile Adventures’ Category

Mobile Adventures Episode 2: Asset management

Thursday, October 18th, 2012


Today I’d like to talk a little about resource and asset management in our little project: Star Force Battleship. Remember this is an ongoing series so if you missed the first episode, you can find it here.

We basically have a few different types of assets to take care of, and ideally, we want everything to be loaded once at the same time so we don’t have any hiccups during gameplay. Here’s a simple breakdown of our assets:

  • Textures.
  • Models exported from Max.
  • Dynamically created geometry.
  • Compiled FLSL shaders.
  • Music and sound effects.

Of all this stuff the most important ones are the models, textures and shaders, mostly because there’s quite a lot of processing before they’re sent to the GPU and, again, we don’t want that happening during gameplay. To make things even more interesting, we can’t just create an entire couple of geometry / material for every single bullet / enemy we have because the’d be just too many and our resources on mobile are already pretty scarce.

The loading process

The loading itself isn’t very special: We just use [Embed] on most of our assets except the sounds and then we start creating the resources we need. The first thing we create are the materials that are the ones that take longer to be sent to the GPU.

Thanks to FLSL we can create very cool effects in a very optimized way, with the best examples being the scrolling background, the “cylinder” texture and the animated explosions. Just in case you don’t remember how the game looks, here’s a commented screenshot:


Let’s take the scrolling background material for example. We load it like this:

We tell Flare3D to load the texture and then we create a new FLSLMaterial that contains a 2D sampler called “texture” that will hold the texture we just started loading. Finally, we upload() the material by hand. This is very important: Flare3D, by default, will only upload material buffers when they’re actually used. While this is a reasonable approach most of the time, specially on desktop computers, here on mobile that would probably freeze our game as soon as we enter the level. By calling it by hand we make sure that by the time we finish our loading state, everything is ready to run.

Something similar is done for our dinamically-generated meshes like the bullets: We create a single Plane instance that will be cloned later. Something like this:

Simple stuff right? Once this mesh is created and uploaded, cloning it to create our bullet pools isn’t as costly as creating and uploading a whole new instance. But pools, my friends, is material for another chapter of this adventure. Let’s call it a day for now Sonrisa

Stay tuned for more!

Mobile Adventures – Intro

Thursday, October 4th, 2012


The last few weeks I’ve been busy with a fun new little project: A mobile game for Android and iOS. As you might remember, this isn’t the first time we talk about using Flare3D on mobile devices, but back then it was a quick proof-of-concept port of YellowPlanet using Flare3D 2.0.48 running on an iPad 2.

FingerAttack-screen2This time, however, things are a little different: I’m using bleeding edge builds of the much awaited Flare3D 2.5 and my target device is way less powerful. The idea is to get a complete 3D game running smoothly at 30 FPS on a Motorola Droid 2 smartphone. We realize that this device is a little old and underpowered, but that’s pretty much the idea, to push our code to the limits. After all, if we get it to run properly on this device, it should work great on anything more powerful. So, challenge accepted! 😀

The idea is to share here in the blog different aspects of this project from time to time and for this first installment, I’ll talk a little about what the project is and what are the main challenges that it presents: The idea is to make a vertical space shoot’em up with full 3D graphics, background music and sound effects. The game must feature enemy squadrons attacking you, plenty of bullets and animated explosions all around. But one picture is woth a thousand words, or so they say.

So, a few topics I’d like to talk about:

  • Asset creation and management: As you can see, there are enemies, different kinds of bullets, the player ship, background geometry and explosions. Since loading and setting up all that stuff can take some time on mobile due to hardware constrains, we have to be very organized and avoid any kind of loading during gameplay.
  • Multiplatform development: Even though the Flash and AIR platforms excel at portability, there are still things to consider like screen resolutions and aspect ratios. We’ll show you how to handle these topic as painless as possible.
  • Lots of collisions! It isn’t just between enemies, bullets and the player, it’s also possible to collide against some of the background elements. Since 3D collision detection can be expensive, specially on mobile, so we had to figure out a more lightweight approach.
  • We want the game to look as good as possible while mantaining a smooth framerate. Animated explosions, scrolling backgrounds and shiny ships / structures, we make use of some FLSL magic to make everything pretty and fast.
  • Object pooling: We must be able to create and destroy items all the time while using as little CPU power as possible and keeping memory activity controlled. We really don’t want the garbage collector affecting our precious framerate.
  • Manual drawing. In order to have more control and flexibility in some situations, we need to draw some objects by hand instead of just adding them to the scene. We’ll show you why this can be useful in certain situations and how it’s done.
  • There are a few more topics that I’d like to talk about but, for the time being, this should give you a general idea of what you’ll be getting each week. Stay tuned for more! :)