Ameen AltajerAI & Search Engineering

Precious Engine/07 of 9

Engine Integration

Embedding the engine in an Android activity through a SurfaceView.

When you want to use the engine on Android devices you'll have to first embed the engine into the activity, Android's form, that is going to play your game. What developers advise you to do is first create a new class, named for example GameView, that will inherit from the class SurfaceView that the Android system uses to render animation.

The reason we do this is that when we build our GameView deriving from SurfaceView, we let Android create two running threads: one that deals with the GUI, and another that will handle our game.

The plan then is to embed the GameView you just made into the activity that is going to display the game. Once that is good we have to give the engine the control to use the screen to render all the objects.

You would say this is hard to accomplish. But I would say that these things need to be done only once for every game you want to make, and when you make it you'll be able to use it every time you intend to make a new game. You could use a template for that. In fact I made that just for you, and you'll find the code for engine integration with the activity in the sample I uploaded along with the engine.

If you feel that you can embed the engine in a better way you're welcome to do so. In fact I would appreciate it if you told me about it.