Wednesday, August 3, 2011

Android Live Wallpaper tutorial

Continuing my Android exploration, I found AndEngine.
It's a great tool to do graphics and the forums are very active and helpful.

Based on a few of the samples that include a multiplayer pong, I decided to go for a Pong Clone as a first approach to Android Games, and see how it works.
The basics are covered in the tutorials and examples in AndEngine forums.

I started installing the engine and examples. They worked great and was easy to read and the code is very readable.
Though as the engine is new and in constant development, it changes faster than the samples found on the web, and some tweaks have to be done to get it to compile.

Then I found the live wallpaper extension and in the forums a Template by Mimminito for AndEngine Live Wallpapers, and it seemed like a good idea to have a pong game playing itself as a wallpaper, so I moved my pong code to it.

I had some troubles at first, figuring out how to move objects around.
For example, the ball:



When the object is created, you can override the update method, and add the behaviour you want to it.
I thought this was going to solve all my problems, but when I got to the paddles, the overriden function cant access the ball position, so I went looking around for info on how to do this, and found that I can override the method
@Override
public void onUpdate(final float pSecondsElapsed)

and put my logic there.

The wallpaper looks great, very retro, and can be found on the Android Market





Here's the full code:

2 comments: