Hi all. We’ve been asked by a few developers how we got our game, GoNinja, to run as smoothly as it does. I wrote a small list in response to a question on a blog post, and I’m reposting it here since I think many of you might find it useful.
-
Preload all images before the start of the gameplay and don’t load any more during it. We keep everything invisible until we need to place it on the screen, and once it moves off the screen we make it invisible again.
-
Corona sqlite database writes are synchronous and slow. If you need to write to the database, batch up as much as you can into one query and avoid making too many queries at all costs. On slower devices the game lags a bit every time you kill a guy since we need to write data for achievements (just one small database query), no way to fix this completely, but it could be a lot worse.
-
Avoid accessing or changing the .x and .y properties of display objects or display groups as much as possible. We only check these once per frame per object and then we cache them so they don’t need to be read again. A lot of people don’t realize that just calling “image.x” too many times can actually be really slow.
-
To reduce memory usage, use smaller versions of some sprites and scale them up. When things are going by fast, people won’t notice a small reduction in image quality on some areas. Keep the detail high on the things that matter.
-
Do not place functions in the global scope. If you have code anywhere that looks like “function doSomething()…” instead of “local function doSomething()…” then you may be unnecessarily using extra memory between scenes. Images that are used inside of these global functions will not be garbage collected on a scene change.
-
On some android devices you might need to go down to 30fps. Single core devices in particular start having audio issues and other problems if you push them too hard. We ended up defaulting to 30FPS for all android devices, but we might bring it up to 60 for the more powerful ones in the future. [import]uid: 135827 topic_id: 27179 reply_id: 327179[/import]
