Jump to content

  • Log In with Google      Sign In   
  • Create Account

We're offering banner ads on our site from just $5!

1. Details HERE. 2. GDNet+ Subscriptions HERE. 3. Ad upload HERE.


Bruce Sutherland

Member Since 14 May 2007
Offline Last Active Apr 09 2012 05:03 PM

Posts I've Made

In Topic: Do you have to use OpenGL for decent 2D on Android?

08 April 2012 - 09:52 PM

I know this post is over a month old but it asks a pertinent question regarding the performance of different 2D rendering methods.

The best discussion of this on Android I've come across is Chris Pruett's 2010 Google IO talk.

You can watch it here:



It's well worth the entire hour of your time if you're new to Android game development.

In Topic: SurfaceView, Canvas, and Threading: Would my Java-esque concept work out well?

08 April 2012 - 09:20 PM

That's one way to do it. Don't fall into the trap of thinking that there's only one way to do something. Do whatever fits your own design and goals. It's easy when starting out to look for that silver bullet resource which tells you exactly how to do something.

I'll tell you for free, it doesn't exist Posted Image.

Another way to use a Thread would be to use a SurfaceHolder inside the class which extends SurfaceView and Runnable. This now lets you entirely contain the game loop inside the RenderingView class, whilst also being a bit easier to understand than the tutorial you posted.

The next step is to decide if Canvas is good enough for your needs or if you should move to OpenGL. The framework I'm current'y writing for myself is OpenGL 2.0 based and has the Android UI thread, a game logic thread and a rendering thread. Once I'm happy enough with the basics I can throw it on BitBucket and you can see how I am doing that.

So,

public class Game extends Activity {
	RenderingView	 renderingView;

	public void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		renderingView = new RenderingView(this);
		setContentView(renderingView);
	}

	public void onResume() {
		super.onResume();
		renderingView.resume();
	}

	public void onPause() {
		super.onPause();
		renderingView().pause();
	}
}

public class RenderingView extends SurfaceView implements Runnable {
	Thread thread = null;
	SurfaceHolder holder;
	volatile boolean running = false;

	public RenderingView(Context context) {
		super(context);
		holder = getHolder();
	}

	public void resume() {
		running = true;
		thread = new Thread(this);
		thread.start();
	}

	public void run() {
		while (running) {
			if (!holder.getSurface().isValid())
				continue;

			Canvas canvas = holder.lockCanvas();
			// Use canvas to draw things here
			holder.unlockCanvasAndPost(canvas);
		}
	}

	public void pause() {
		running = false;
		while (true) {
			try {
				thread.join();
			} catch (InterruptedException e) {
				// wait
			}
		}
	}
}

In Topic: I need a real android phone now - help

08 April 2012 - 08:49 PM

Google have some statistics on their developer pages which you may find useful.

This page shows the breakdown of Android versions being used to access Google Play.

http://developer.android.com/resources/dashboard/platform-versions.html

You can see from this that versions 2.1 and below already only account for less than 7% of the devices in the wild.

However, the decision on which versions the app will support will be based on whoever you're going to be working for, but for new developments it makes little sense to target versions older than 2.2 as lots of performance improvements and features (such as JIT and OpenGL ES 2.0) were added in version 2.2.

In Topic: Developing different views for different android devices?

08 April 2012 - 08:43 PM

I think what you're looking for is a concept in the Android SDK known as Fragments.

You can find a full explanation of these here:

http://developer.android.com/guide/topics/fundamentals/fragments.html

PARTNERS