Tuesday, December 4, 2012

Tips & Tricks for Android Game Development


Here is a list of best practices I learned while developing the Android version of Tales of Illyria. This is based on my experience and some of these things may have changed.
  1. DO NOT think of every screen as a separate Activity.  If you do this you will have to manage the life cycle of every Activity and the associated view and thread, not to mention all of the input events. Starting and stopping activities with intents is a little cludgy as well as sharing data. Instead create your own windowing system which you manage yourself, mine is called Menus.
  2. DO NOT create a single Paint object and then set the properties of it as you go, this creates very messy code. Instead create a static class called Paints with static members of type Paint. Think of it like CSS for HTML.
  3. DO NOT put your graphics and sounds in your project. If you do this every time you test your project you will need to wait while the graphics and sounds are loaded. Also loading graphics and sounds from the R class is cludgy because you cannot dynamically reference them. Instead put the graphics in external files you download separately to the device. This is why so many games have their own installers.
  4. Create a single static class with static members pointing to your game data this way it can be easily accessed every where with out passing it around.
  5. Instead of passing the Activity and Context around create a static reference to it or use ThreadLocal.
  6. Save your game using serialization instead of text files this will save you a lot of time.
  7. Create a static class for managing sounds. For sound effects use SoundPool for background Music use MediaPlayer
  8. When using Canvas.scale() do not make continued calls to a scaled canvas instead scale the entire canvas one time. How do you do this? Draw everything to a separate canvas unscaled then get the bitmap associate with that canvas and draw that to the scaled canvas. This will give you a huge gain in FPS.
  9. Always recycle your bitmaps when done with them if you don't you will run out of memory.
  10. Use Interfaces for your UI elements.
  11. Create Util classes. I have ZipUtil, BitmapUtil, LineUtil, FileUtil, AndroidUtil, NetUtil.
  12. Consider using DHTML for creating your development tools and a database for saving your data. This way you can have web based tools for your designers to use. Tales of Illyria has four web based tools, World Editor, Event Editor, Character Editor and Party Editor.
  13. Don't develop your own sounds use SoundDogs instead.
  14. Use OGG format for all sounds and music. Use PNG for all graphics. However when you do not need transparencies use JPG as they take less memory and draw faster.
  15. If you are just starting to learn Android I would recommend learning a cross platform tool instead.

2 comments:

  1. Great information here. I am so delighted to be here.Thanks for sharing in detail.
    Very helpful and useful blog.Thanks for share.
    android app development perth | android app development sydney

    ReplyDelete
  2. Helpful information about app development company & services! Nice blog.
    app development company perth

    ReplyDelete