Use of Wakelok and Stand-By in Android Games

When to suppress the Stand-By Mode in Games?

This depends on the kind of game you want to develop. If the player has to interact with the game constantly or if he only has a limited time to draw, the stand-by mode usually doesn’t need to be disabled.

It’s relevant to disable the stand-by mode only in video-or demonstration modes, when the player doesn’t need to interact at all for a certain time. It’s more important, how the game reacts on the stand-by mode. It’s the best solution if a game automatically switches to the pause-menu on a stand-by, where the player can easily resume the game.

How to suppress the Stand-By Mode?

You use so called “Wakelocks” to suppress the stand-by mode on a Android Phone. Here I show you a sample implementation using the game-engine e3roid. It’s very important to release the Wakelock before exiting the game.

Manifest:

You need to request the nessesary permision:

<uses-permission android:name="android.permission.WAKE_LOCK" />

Main Class:

public class StoneSetter extends E3Activity {
private PowerManager.WakeLock wl;
public E3Scene onLoadScene() {
   ...
   PowerManager pm = (PowerManager) getSystemService(Context.POWER_SERVICE);
   wl = pm.newWakeLock(PowerManager.FULL_WAKE_LOCK, "SomeTag");
   wl.acquire();
}
 
public boolean onKeyDown(E3Scene in_scene, int keyCode, KeyEvent event) {
if((keyCode == KeyEvent.KEYCODE_MENU || keyCode == KeyEvent.KEYCODE_BACK)){
   exitGame();
   return true;
}else{
   return false;
}
}
 
public void exitGame(){
  wl.release();
  finish();
}
 
}

Game Engines: Including the the first game elements in my Android project

The next step after setting up an Andorid project was to include the first game relevant elements into a prototype. The target is to put multiple moving or animated graphics (sprites) and paint them into a canvas that will regularly be displayed on the screen. To accomplishing this, a nice class hierarchy has to be created to easily handle and organize sprites.

By coincidence i stumble over two freely useable 2d game engines, which handle exactly these topics – and even more. I have had a detailled look at both engines. Here you find a short summary of my experiences, that I’ve made with these engines:

e3roidhttp://www.e3roid.com

E3roid is a relatively easy to learn 2d game engine for the Android. There are a lot of example source code available that perfectly describes the way to use the engine. There is a good Tutorial in the e3roid-Blog available, which makes the start even more easy.

Basic functionality is in addition to sprites and animated sprites also an easy menu-function and the support for so called “Tiled-Maps”, which helps you in building game-worlds quite easy.

Andenginehttp://www.andengine.org/

Andeninge is, like e3roid, a 2d game engine for Andorid. The engine seems to be more difficult to understand as e3roid. Many functionalities are quite similar to e3roid (because e3roid is been inspired by Andengine in some places). But it’s not only more difficult, but also looks more professional and complete than e3roid. Additional functions in Andeinge are for example: Audiosupport, a* (a-star) algorythm for path-finding on tiled maps, and a multi-touch onscreen controller.

The Andengine-Community is very active, so that you can quickly find solutions for your problems or get some inspiration by others.

My conclusion:

Who prefers to have a quick start should have a look at e3roid. You can have nice results within a short time. Especially if you are new to the topics, I’d really recommend to use this engine.

If you prefer the more professional way and you require a more complete game engine, you should prefer to use Andengine. The more difficult start-phase will soon be rewarded when more complex questions arise.