Take the 2-minute tour ×

I am about to port a game that was initially written for iOs and I am having some doubts how certain things should be done.

I have been looking many of the examples of the game loops for android, and almost everywhere the game loop is designed to run in separate thread and not in main UI thread which seems fine and logical to me. However, my game scene is combination of OpenGL graphics and standard android views (buttons, labels, etc...) and by design, the primary game logic and OpenGL drawing would be done in separate thread and rest of the standard stuff would be done in main UI thread.

In many situations, I will need to call functions that should run in game thread from main UI thread and vice versa. As a very basic, simple example, when user performs touch (which is detected in UI thread) the event should propagated and be processed by the game thread.

Do you know some good mechanisms or patterns on how to such cross thread interaction? Is there a simpler solution to a game loop, maybe by not running loop in a separate thread?

share|improve this question
Please do not post exactly the same question on multiple sites, we can move questions automatically if you happen to post on the wrong one. –  Yannis Rizos Apr 10 '13 at 23:12

1 Answer 1

up vote 1 down vote accepted

If you run the loop in a separate thread you will need to keep it synchronized with everything else that will be going on. This should provide you with insight though: http://gamedev.stackexchange.com/questions/651/tips-for-writing-the-main-game-loop

I've not programmed on Android, but I have programmed in Java. If you want to see an example of my game loop you can get the code here: https://github.com/moorej/RetroPlexjava

share|improve this answer

Your Answer


