I have now completed version 1.0 for TouchMagic and it is now available for testing! The application is not currently available on the Android Play Store, but if you wish to try it out leave your email in the comments below and I will send you a copy of the APK.
So after the release of the first Beta for Tanker, I have pretty much put development of Tanker on hold; the only thing I have time to worry about is TouchMagic and getting the game released in time to the Android market in order to gather a good set of results before I get to writing my dissertation. As I’m currently put on for 3-4 days a week at my current job as a phone salesman, this isn’t easy.
But it is coming along OK. My third mini game is now complete: a game that has a set of light bulbs wired together with only one light bulb on. The player must drag power from the first light bulb to power on all the lights. A simple game in concept, but the number of lights and positions are randomly generated, so sometimes it becomes a bit difficult to see which wire goes to which light!
With this complete, it is now time to gather data. Figuring out how to do this was a pain in the neck. I initially wanted to fire an object file over a TCP connection to a Java server that I had running on a static IP. For a number of reasons this idea crumbled as I did more and more research. However the main factor was thus: I was building this for a mobile application. Instead of designing my own TCP protocol, I was much better off using HTTP which would handle packet loss much better. The java server also seemed a bit heavy of an implementation for what I was doing, so I am instead writing a PHP server. Lastly comes how to package and send the data. I have decided to send the data as an XML document.
Now there are multiple ways to serialize XML documents from Java. I intially started doing this using JAXB, and all was going well until I realised one problem again relating to mobile development: The libraries for JAXB were over 12MB in size. For a mobile application, that is a lot of memory. I soon hunted around for something better and more lightweight. Eventually I stumbled across Simple and this tutorial on how to use Simple with Android. The library totals up to around 300KB in size; a lot more ideal for a mobile application. And personally, I found it a little easier to learn and understand than JAXB even though there seems to be a lot more support for JAXB on the internet. Bottom line though, if you ever want to write any XML files on the fly in Android, use Simple.
Now that is done, I can now move on to saving the XML files to my server which is dead easy, and then creating a few more minigames for TouchMagic.
First mini-game for TouchMagic is now complete; dragging one sprite around the screen to a target area. Now to move on to something a little bit harder, physics.
Andengine’s physics support is done through andenginephysicsbox2dextension, which makes use of the Box2D Physics Engine. Using the examples provided and some of the simple tutorials out on the web, the physics engine is pretty easy to use providing you are dealing with simple objects like circles and rectangles. I however needed more complex objects than this, and was daunted by the fact of having to specify the edges of each object I wanted (especially objects based of circles). After a bit of digging around however, I came across this tutorial written by Johannes Borchardt. He has put together an AndEngine extension that makes use of a the program PhysicsEditor. PhysicsEditor will take an image of an object and trace around the object to generate a polygonal body for the image, making it really easy to represent it in a wide variety of gaming engines. This really looks like a must-buy for any game developer and can seriously cut down on the work developers have to do for their physics based games.
So it turns out, AndEngine is a pain in the neck to learn…
As mentioned on many places around the web, AndEngine’s main disadvantage is that there is no available documentation. Most people also say however that there is a very helpful community out there to support you and provide tutorials to help you along the way. Unfortunately one must bear in mind that the second version of AndEngine (GLES2.0) was released in December 2011, so any tutorials written before that date may contain code that will not work if you are trying to use the latest version of the engine.
So my most of my day has been dedicated to research, and filtering through all sorts of AndEngine stuff on the web. I have been through the whole setup process already to get the engine working on one of the university lab computers (which wasnt easy because the lab systems only have Android 2.1 and 2.2). Thanks have to go out to RealMayo and his set of tutorials. Ive downloaded his copy of AndEngine from github and managed to get it working without too much trouble.
After installation comes the learning process. Now there is a lot of information out there on how to do X and Y with AndEngine, but not much on how to design the architecture of a game. Eventually, I stumbled across Jimmar’s Invaders Clone Tutorial which not only gave me a great understanding of the game architecture in AndEngine, but was also relevant to GLES2.0.
So I had a read, and began coding up my first implementation of TouchMagic. The resultant architecture works as follows:
- Create a class which extends BaseGameActivity. This works pretty much like a normal Android activity, so it also needs to be registered in the AndroidManifest.xml file. You set up the Overriden methods as normal, creating a camera and a scene which in most cases will be the opening splash scene for the game.
- Create setCurrentScene in your BaseGameActivity. This two lined method handles the swapping of different scenes within the game
- Create all the scenes for the game. And then swap between them as required with setCurrentScene.
And that is basically it. BaseGameActivity is used as a controller to administer several different scenes in a game (like the splash screen, main menu, and the game itself). Currently I am unsure why one would want to then have multiple activities within their game, but I may find out why later. As of now though, TouchMagic has a Splash screen, menu screen, and a simple game where one can drag a sprite around the screen. I think its time to call it a day