views:

1371

answers:

2

Hello, I'm trying to learn how to make video games on Android, and therefore I'm needing to get some decent tutorials going on how to make graphics on Anroid using the SurfaceView object. However every single graphics tutorial I've tried (mainly SurfaceView stuff) has failed. Please note that I don't want to use XML, as it is out of my element, and Google just wants to sell that technique on the advertisement of neatness, which I can do programmatically.

One major problem I've run into is that there are many tutorials, both from Google and from third parties, with code that uses the import android.opengl.GLSurfaceView command, or either imports a subset GLSurfaceView, and that never works on my IDE. Every time I try to import either one of those, Eclipse wants to say that it basically doesn't recognize that package. The strange thing is that I CAN import android.opengl.*, although that still causes some of the code in those packages to be referring to unrecognized types and/or methods.

After trying to fool around with the first problem for a while, I noticed that the Lunar Lander example didn't try to import either one of those two problem libraries. So I pulled the code and referenced resources for that into one of my infant projects, leaving everything else in that project unused. Of course I did change which package the Lunar Lander code was in and changed the class name in LunarLander.java or whatever, but that should not matter. I was able to get the thing to build in Eclipse. However when I went to run it, it would do nothing but crash. Without showing any Lunar Lander graphics or anything, the emulator would just give me this error message basically saying that my App has stopped working unexpectedly and makes me close the App.

1) What's the deal with the issues with the opengl.GLSurfaceView package? 2) What's the deal with the Lunar Lander example? 3) Where's a good, firm tutorial on how to make video games for Android

Thanks.

A: 

Are you building games in 2D or 3D? I can't speak for 3D, but I've built some simple 2D games and SurfaceView was more a hindrance than a help. The emulator only simulates one core, so you don't really get a performance benefit on the drawing. Furthermore, the thread overhead and maintenance is a pain to deal with and prevents many capabilities (I spent a few hours just trying to launch a GameOver dialog from various configurations, and the extra thread prevented this from happening).

An alternative to SurfaceView would be to implement your own class that extends View, and override onDraw(Canvas) to draw whatever you like (this is what me and my friends did).

To answer your points:

  • I've never worked in 3D or used Android's OpenGL, but Eclipse (if that's what you're using) can be a bit temperamental with locating Android resources. Do the rest of your classes load?

  • Lunar Lander shows you how to create and destroy a view extending SurfaceView and SurfaceHandler. Again, there may be contexts for which SurfaceView is a great choice, but if you're just starting with Android and building simple 2D games, I don't think it's essential.

  • Good tutorials are hard to find. I learned enough to make this 2D game from spending a few hours with the e-book version of Hello Android.

Some buddies of mine and I are working on games for Android this semester, we've also set up a blog that we hope to make a resource to others as the semester goes on. Sadly, there's not much on it at the moment.

Good luck!

paul.meier
A: 

What is the API level for the project set to?

Hans