Optimising Your Mobile Game (Less Lag, More Awesome)
In this guest post Daniel La Rocca, Lead Designer at Evoke Method, shares his optimisation tricks for making sure their 3D destruction game Alienation runs smoothly on any smartphone, old and new.
We have (it sucked) and we realised it could have been avoided. It was a combination of all our small little errors and carelessness snowballed into one massively crippling issue: lack of speed.
We must have forgot to put precognitive knowledge of the near future on our character sheets because we kept making mistakes and kept being careless.
If we’d kept going like that our game, AlieNation, would’ve become unplayable. Luckily we stopped, gathered our thoughts and hailed game optimisation as our newly crowned King of Development.
Why we Went 3D over 2D
We decided to create a 3D destruction game to fill a niche in the market – and considering the positive reception we’ve received from playtesters and local media, it’s surprising why most destruction games go 2D instead! Sure you might have to work a bit harder to optimise your art pipeline, but 3D is the way destruction should be – it feels so much better to play.
Efficiency and optimisation make me all warm in areas that don’t even make sense, so here are just a few things that I kept in mind and constantly asked my team for to make sure our 3D destruction game kept playing smoothly.
When to go 3D (when to stay 2D)
The first critical lesson I learned as a 3d games artist is to keep everything as low poly as possible: don’t use any more vertices than you need and if you have detail in your models – keep it in the texture. Our buildings are modelled for their silhouette with every single grate and rusty detail textured in.
When we first created Professor Vogel for the in-game HUD and GUI Menu, we tried a 3D model of him, but ditched that in favour of flash art on layered planes. It ran smoother, looked better and provided a significantly better result than using a 3D model! We did this because all the detail we needed to keep Professor Vogel looking cool and matching the art style we could easily achieve with animated 2D textured planes.
I still cry tears of joy looking at this.
Lazy Texturing is Lazy
Texture sizes are where most artists fail in regards to optimisation because textures TAKE UP A LOT OF MEMORY.
Talk to a few artists, I reckon many of them create their textures in a relatively comfortable size such as 512×512. This is reasonable, and there’s nothing wrong with this, the only problem comes when the artists don’t downsize their texture to a more reasonable size before export.
A smaller efficient texture file can look just as good as a massive texture file once you get that asset in game! But if that artist did all their work at the wrong texture size, unfortunately all the beautiful detail the artist drew in and spent so much time on can get completely obliterated when it gets downsized.
To avoid this problem completely, I recommend artists either clean up their art after downsizing, or texture in the same resolution the file will be in game. That way you have control over every pixel in the texture.
On File Formats, Reusable Textures and Shaders
PNG is the lesser of many evils. It does lossless image compression compared to lossy JPEG compression, it doesn’t do alpha as great as TGA does – but it does do compression and alpha mapping good enough to make it better than the other file types.
Pretty much the lesson is:
Improper sizes +improper file formats = too much texture memory used = slower game = finding and downsizing texture = lost detail = lost time = very sad artist = very angry art lead.
Another extremely helpful thing involving textures is to re-use them whenever you can. Obviously this should be true with any asset in your game but in our personal experience on Alienation, instead of making new texture files and using up more texture memory on barely visible weapon and metal objects we re-used the building texture files on these small trivial objects! With a bit of UV tweaking you’d never know they were recycled textures.
One very important thing to note is the use of appropriate shaders. Sure the bumped specular shader looks fanfuckentastic on everything it’s put on, but there are specific mobile shaders out there that are designed for efficiency.
In our case, shaders were easy, they were already built into Unity.
When to Alpha Map vs Building it into the Mesh
The brilliant thing about alpha mapping is that it can make part of an object transparent, very easily and relatively cheaply [Editor’s Note: When we say “Cheaply” here we mean cheap in terms of processing costs. Everything pixel, polygon, shader, light, particle and bone costs your game processing power.]
However in some cases, a mesh is actually much more efficient than an alpha map! For example, when creating the wheel on our Clinker enemy it was incredibly cheaper and actually easier to model in the gap in the wheel than to have to texture it in.
I realise that I just contradicted myself about keeping the detail in the textures, not the mesh. But it is the ability to distinct between when to use what that makes you not just a game artist, but a great game artist.
Particles, draw calls and physics
Now, as with any game, visual feedback is absolutely critical to engaging with your player. Without feedback on their actions your game becomes boring, confusing and as interesting as a full time career as a professional paint dry watcher (yes, this is job exists, no im not shitting you, and yes this is hilarious).
Back on the topic of FEEDBACK: particles are a FANTASTIC way to convey information to the player! Ranging from spark particles from a bullet that hits a wall, to blood particles from when that bullet ricochet into a Nazi.
There are a few things that can go wrong with particles, one involves the texture file size for the particles, which, if you’re reading this blog post from top to bottom then congratulations – you’re already aware of my texture size rant and you’re a better person for it.
If you’re reading this segmented after skipping section headlines and haven’t already read my rant about texture file size, go read it. I guarantee you’ll instantly become sexy and more appealing to the opposite gender. [Editor’s note: Take that Neil Strauss!]
Another downside to particles that most people fail to realise is that increasing the number of particles does NOT increase the amount of awesome – it just slows down the game. There are two different ways someone can make a particle effect: one way involves someone using the smallest number possible in the emitter to achieve the best result, the other way is to crank the number to 2000 and call it a day.
The only reason you don’t see 2000 particles per emitter in every game out there is because of draw calls.
A draw call is made for each separate object within the scene (each draw call made increases lag time). In the case of particles, it is very easy to overload on draw calls
Now, I love me some particles, but when I see some junior artist look at a nice efficient particle effect and think, “10 particles per emitter?? Madness! This would look much better with 2000 particles per emitter”, I feel incurable sadness and near physical pain.
I…..just..what??? Why would you even do that? Bad junior artist. No Redbull.
Physics (Closest Thing we Have to an Insta-Fun Button)
There is nothing cooler than hitting a building with a well aimed shot, watching it fall over all cool and dramatic like and you end up making stupid sounds like “fhwoar” and “Michael Bay”.
Why does this happen you ask? The thing i just said happens because of sweet and sexy physics!
I let the programmers take the reigns when it came to our physics, so everything i’m about to type came from the indecipherable language of programmer, through the translator-language-barrier to this artist and from this artist’s pixel pummeled brain to you the reader, so bear with me here.
Physics updates SO many times per frame, what they update is their position, speed and anything else relevant to their motion. The amount of times the physics is updated ties directly to how fast the game runs and a great way to get a faster speed is to reduce the amount of updates per frame.
This is a sure fire way to get your game running faster, but it may mess with the sexiness of your physics and it is very important to get this balance of updates per frame to be able to have cheapish and efficient physics.
An example we experienced was when we reduced how many times our physics updated per frame. Our ball might update infront of a wall, travel into the wall during the downtime, then update inside the wall and launch itself out either side of the wall and trust me on this, balls coming out of walls is NOT realistic…I think.
It takes our programmers a few more minutes of tweaking to get the best balance of uninterrupted and efficient physics.
Lights and Skyboxes
Two things that im going to touch on quickly (mostly because im hungry and need dinner) are lighting and your skybox.
The amazing thing about skyboxes is that you don’t have to use them for sky (I know right?!?)!
A fantastic way to use them is to include background art on them (like a matte painting in film) which is a cheap and easy way to add a huge amount of background art and atmosphere to your game.
Lighting is a harsh mistress and i’m going to say this straight out: for mobile, you better get used to directional lights, and if youre feeling like a lucky punk, maybe a few point lights. In Alienation, we put in a spotlight , but after toiling night and day researching lights (I lie, i just Googled unity lights), I found that spotlights were one of, if not THE most expensive light you can use for mobile games.
Taking each of these suggestions individually, your game won’t change an incredible amount.
But combine everything above and apply all of them in your optimisation: you game will transform completely from something that crashes more than a teenage driver, to something that runs so well it brings a tear to your eye. A tear of joy.
Evoke Method is a Sydney based startup indie game developer focusing on making fun games that satisfy on a primal level. After having a blast working together on a student hack-n-slash project named Immortalis, they decided to form up as an indie studio. They are currently working on Alienation, a 3d handheld destruction game for the iPhone, iPad and iTouch. Follow them on Twitter, like them on Facebook or check out their website!
[Want regular bits of indie beamed straight to your inbox or feedreader of choice? Visit the Subscribe page!]