After all the stress in the last few weeks i decided to use 2 hours of my spare time to prototype a game with libgdx. It was more or less a small exercise to get a bit more familiar with Box2D. First off: doing this with libgdx was plain awesome, at no point did i curse its design. I also used the Box2DDebugRenderer so i didn’t have to write a single line of rendering code myself. For prototyping box2D based games that’s just awesome.

The game that i tried to implement is called Super Fill Up. You can play it over here. It’s a causal variation of the old game called Qix (which i played to death on my Game Boy). The basic premise: fill up 66% of the screen with balls (yeah, it’s funny) by clicking on the playing field. While you hold your mouse button down a ball will spawn beneath the cursor and grow. On the playfield there’s a number of other smaller balls which you should avoid while growing your ball. Each level adds more of the evil balls so it gets harder and harder to fill up those 66% of the playing field.

I reimplemented this with libgdx and the help of Box2D. All elements are actually simulated by Box2D, getting the evil balls right was surprisingly simple. The growing part needed some trickery as you can’t scale Box2D bodies. You basically want to create and destroy a growing ball each frame. Here’s how the game looks rendered with the debug renderer:

You can find the apk at http://file-pasta.com/file/10/fille-android.apk. Note: IT WILL CRAWL ON FIRST GEN DEVICES, SO DON’T COMPLAIN! It’s due to the debug renderer which is not intended to be used on Android devices.

Now the game mechanics are nearly 100% identical to the original but it fails to entertain on an actual touch screen device. Here’s the reason:

Occlusion is your worst enemy when doing touch based games. “Super Fill-Up” works great on the desktop as you don’t occlude a lot of the playing area with your mouse cursor. This way you can estimate at any time which evil ball will hit from which direction. You do not have to memorize the positions of the evil balls. On the touch screen device you have to build a full mental image of the playing field and all the moving objects as your thumbs will occlude large portions of the screen. This considerably lowers the fun of the game because building this mental image is hard, especially with a large number of objects on screen.

Conclusion: before implementing a full blown game think about the impact of inevitable occlusion!

  • Share/Bookmark
 

Splodey!

Mark Neil was one of the first people to use libgdx and its box2D wrapper earlier this year. He developed an original Android game called Splodey and is now preparing to release it to the market. Go checkout his site at http://www.pointergames.com/ to find out more about Mark’s company and games.

  • Share/Bookmark
 

Help Me Write a Book!

I just finished writting the proposal for the APress book “Beginning Android Game Programming”. This includes the full detailed Table of Contents. I would love the get feedback from you people out there on the contents of the book. You can find the table of contents at http://www.file-pasta.com/file/0/toc.pdf.

What i want from you:

  • What do you think of the structure of the toc?
  • Is there anything missing for a beginner’s book?
  • Is there anything you’d like to see added?

I will send this proposal to Apress tomorrow evening. Maybe i’ll wait till tuesday evening if i get a lot of feedback to integrate. Thanks for any replies!

  • Share/Bookmark
 

I’m working a tiny bit on an application called FaceIT from time to time which uses a shitload of bitmaps in the two activities it consists of. Note that i’m not responsible for the original application but just started fixing some bugs in it a couple of weeks ago. The app suffers from silly out of memory exceptions due to Bitmap data not getting freed as the Bitmap objects in the VM don’t take up enough memory so the GC collects them and frees the native heap memory associated with them (Which the GC knows nothing about). So i poked around a little and found out that there is actually a way to get the native heap memory usage of an app on Android!

android.os.Debug.getNativeHeapSize();
android.os.Debug.getNativeHeapFreeSize();

Both return the respective sizes in bytes. With this it is quiet easy to monitor native heap allocations that happen with say Bitmap instances.

All hail Android! In other news: Collada is a bitch…

  • Share/Bookmark
 

Crash Reports with Acra

I instrumented Newton with the acra library today. Acra registers an UncaughtExceptionHandler (which is also available in desktop Java) and everytime your application crashes bad on a user’s device it send an error report with information such as android version, phone model plus stacktrace to a Google spreadsheet you set up for that purpose. The steps to include this in your application are totally easy:

  • Create the Google spreadsheet as lined out in Arca’s Wiki
  • Create a class that extends CrashReportApplication and implement the getFormId() Method, returning the form id you got from your spreadsheet
  • add android:name=”YourCrashReportApplicationClass” to your AndroidManifest.xml file
  • Crash Reports!

I especially like the solution of using Google spreadsheets for this kind of crash reporting. It also works on devices < 2.2 (down to 1.5) which is a definite plus. Finally you can add your own reports besides standard crash reports at any point in your application. With this feature you could for example log the average FPS of your game.

I used the standard crash reporting facilities of Acra and behold i got crash reports!


java.lang.NullPointerException
at at.knowcenter.pfx.gui.widgets.Label.dispose(Label.java:60)
at at.knowcenter.pfx.gui.Gui.removeWidgets(Gui.java:170)
at at.knowcenter.pfx.gui.Gui.render(Gui.java:136)
at com.badlogic.newton.game.MainMenu.render(MainMenu.java:167)
at com.badlogic.newton.game.Game.render(Game.java:126)
at at.knowcenter.pfx.backends.opengles.OpenGLESApplication.onDrawFrame(OpenGLESApplication.java:317)
at android.opengl.GLSurfaceView$GLThread.guardedRun(GLSurfaceView.java:955)
at android.opengl.GLSurfaceView$GLThread.run(GLSurfaceView.java:887)

Now that is nasty. Gui widgets in Newton are initialized in a lazy fashion. If the user is fast enough i try to dispose something which has not been initialized yet.

I hereby fully recommend the use of Acra in your application! The code is solid and doesn't do anything nasty (e.g. send your stats to a 3rd party).

  • Share/Bookmark
 

Deadly Chambers

Fellow developer Robert Green from Battery Powered Games released Deadly Chambers a few weeks ago. It’s an action adventure type of game where you try to escape various levels by shooting anything that gets in your way. It’s a nice pick up and play game and very polished. Here’s the trailer.

I could follow some of Robert’s development over the last couple of months in a couple of talks we had via GTalk. He put a shitload of effort into this game and i think it shows. Along the way i got to know some of the technical details of Deadly Chambers which are quiet impressive for a guy that wrote his first full blown 3D game (Light Racer 3D doesn’t count :) ). Robert’s using a couple of old school techniques which work quite well on all those mobile devices out there. Lighting is mostly static from what i understand. His artist mastered the black art of generating light maps with Blender which gives the levels their nice look. The interesting thing is that the lightmaps as well as the textures are adapted to the device the game runs on, the better the GPU the higher the resolution of the lightmaps and textures. This makes the game run well even on those punny little MSM7200 chips you find in the G1/Hero.

The next piece in the puzzle is animation. Robert uses plain old MD2 interpolated key frame rendering. Modelling was performed in Blender, the export script seems to work nowadays :) . Probably the biggest problem is the collision detection. He too stumbled across the articles by Peroxide and implemented those algorithms, stumbling over the same pitfalls i did. Calculating the intersections between ellipsoids and triangles is a pretty costly computation so you better first filter which triangles you send to the collision detection. For this Robert employed one of the oldest spatial partitioning schemes known as an Octree. You can query which triangles intersect a axis aligned bounding box with such a thing pretty fast so that makes it an ideal candidate for preselecting potential colliders before actually calculating triangle/ellipsoid intersections.

Along with the octree comes a portal system which uses manually placed portals for culling computations. It works pretty well and it seems manually creating the portals is still the way to go as automatic portal generation often needs manual post processing.

For all things GUI Robert went with plain Android GUI programming. I wouldn’t go down that rabbit hole myself to be honest, lacking the knowledge needed to skin and modify the Android GUI so it fits my game programming needs. However, the end result Robert came up with is incredibly well done. One wouldn’t be able to tell that it’s vanilla Android GUI stuff he’s using for his menus. The only place where he uses custom OpenGL GUI things is in game for the HUD and other things.

He included a shitload of input methods for the game, the multi-touch one being probably the most popular (but non-functional on first gen devices). By placing the analog sticks and buttons into opposite corners and some event filtering he was able to somewhat circumvent the multi-touch problems the N1 and Droid have. It is not a 100% perfect, but it’s the best multi-touch implementation i’ve seen so far.

All that being said, the game is really fun and you should check it out. There’s a demo version to get your mouth wet and a paid version for currently 2.99$. The game is great and the developer behind it knows his shit. So go out an buy a copy! Here’s the QR to the market for the full version (Click the QR code if you are on your device):


Btw, all the art and animation was done by Ryan Foss. He has a very interesting blog where he documents the making of Deadly Chambers. Go check it out!

  • Share/Bookmark
 

libgdx release 0.6

It’s been a while since the last libgdx release. Today we celebrate the release of libgdx version 0.6. Lots of bug fixing, especially with respect to the box2d wrapper which seems to be quite robust now.

One new feature is a simple to use AudioRecorder which you can instantiate via the Audio interface.

Another new feature are some changes in the Box2D API. Fear, i only added new stuff and didn’t change old stuff. The most notable additions here are the Box2DDebugRenderer, which allows you to easily visualize your box2d world as well as the implementation of the Body.getTransform() method which is needed if you want to get the position and orientation of a fixture attached to a body. Check out the Box2DDebugRenderer on how that can be used for this purpose. Of course the Transform class is also properly implemented. The rest of the changes are mainly bug fixes.

What’s maybe interesting for many of you out there are the extensive examples for box2d with libgdx that you can now find in the test project. I talked about them in the last post, so i won’t do it again here.

What’s next? libgdx 0.7 will get multi-touch support (which frankly is nothing anyone sane would use at this point in time given the lack of proper multi-touch devices apart from the Samsung Galaxy S and DroidX). Xavier already started on TMX tile map support, i have yet to look into that. Finally the MD2 loader will get included in stock libgdx.

  • Share/Bookmark
 

Libgdx Box2D testbed

I found an hour today to continue working on porting over the original Box2D testbed tests. The ported testbed is very similar to the original one in it’s design. There’s a Box2DTest abstract class which handles things like creating all the rendering resources, mouse input and so on. All tests derive from this class and most often only implement the createWorld() method that populates the world with objects.

The class TestCollection ties all tests together and allows cycling through the tests by pressing the space bar.

Both things are pretty unexciting, porting the tests is also not really that impressive but rather tedious. The last piece in the puzzle is a renderer which can render the physics world. For this i wrote the Box2DDebugRenderer class, located in the main API so you can also use it when trying to debug your games. It uses an ImmediateModeRenderer internally so don’t expect the performance to be stellar.

Here’s a video of the tests ported so far. I could iron out a bug in the PrismaticJoint and a few other things along the way and all seems to work well. Richard of Rokon fame reported a bug in the default CollisionListener which i couldn’t reproduce. The CollisionFilters test also proves that my implementation of that is indeed correct. I could imagine that not being careful with your shorts (16-bit integer you pervert…) might be a problem in Java, so watch out for that.

Video footage taken on my trusty netbook with software OpenGL so the performance sucks a little :)

Libgdx 0.6 will be released on sunday with all those nice fixes. I hope to be able to port the rest of the tests over (won’t port raycasting and presolve tests yet though, that has to wait).

  • Share/Bookmark
 

I signed a contract today with Handmark, partner of a lot of OEMs and carriers, mainly in the U.S. from what i could gather. They will likely bundle it in some form with future Android devices, or publish it on their own market targeted at Sprint customers. No real details where given. In any case, any publicity is good publicity.

I know i’ve been kinda slow with additions to libgdx lately. Rest assured, i still work on it, albeit i only iron out some bugs and slowly but steadily increase the test coverage of Box2D. The next release (0.6) is scheduled for next sunday, it adds some small but important modifications to the Box2D wrapper along with a debug renderer for testing (which should only be used on the desktop! it’s slow on devices! TAKE NOTE!).

The future of libgdx looks as follows: i’ll add the mod player capability available in Andengine (yes, i too can “steal” code :) ), add support for the TMX tile map format, clean up some dirty interfaces/classes (camera classes, i’m looking at you!), include the MD2 loader i wrote back in January for the tutorial (with fixes from Moritz, thanks!) and try my hands on a wrapper for Bullet. I’ll also stop being lazy and add a multitouch handler for Android so the pointer parameter of the InputListener methods are of actual use. Don’t expect any miracles on devices such as the N1 or Droid though, their touch screens still suck!

All this (expect the bullet wrapper) should be done by the end of august if all goes well and my work load at my day job decreases a little. I’d love to get some other people on the board which could help me out, but i guess the libgdx community is more or less non existant at this point :)

  • Share/Bookmark
 

Nicolas send me a his benchmark suite for libgdx, AndEngine and Rokon. Each engine renders a scene of 32×32 pixel sprites in a grid, a total of 336 sprites, filling up nearly all of the screen. I performed the tests on 2 devices, a Hero with 1.5 and a Nexus One with 2.2

Rokon didn’t start on neither my Hero nor my Nexus one.

AndEngine:
- Hero: ~17fps
- Nexus One: ~41fps

Libgdx:
- Hero: ~51fps
- Nexus One: ~51fps

Yes, you read that right, the libgdx version, which uses the SpriteBatch class for rendering, performs equally well on both devices. Now, in my opinion the test is not entirely fair as AndEngine has to perform a lot of other stuff besides the rendering. However, the main reason why it sucks so much on the Hero is that each sprite rendering issues a lot of glTranslate/glPushMatrix/glPopMatrix commands as well as rendering each quad seperately (the VBO containing the vertices is bound only once though).

You can find the source for the benchmark here.
An apk can be found here.

The more i see these semi-scene graph engines like Rokon, AndEngine or Cocos2D on Android the more i believe that they are not the way to go. You can’t please every genre with these engines and if you have to get better performance you’ll have to dive deep into the source of these engines and modify it. Simple puzzle games or your average Snake clone are a no brainer with those engines. However, something like Replica Island is pretty much out of reach when using these libs at the moment.

I still believe that especially beginners in Android game programming should start out with AndEngine & co. Their nice APIs are much easier to use than the down to the metal approach of libgdx (altough it has nice helper classes in the math and graphics package which should ease your programming pain a lot).

  • Share/Bookmark