Sign up ×
Game Development Stack Exchange is a question and answer site for professional and independent game developers. It's 100% free, no registration required.

I am building a tower defense game for android where you have to defend the base from mobsters who have a bounty on your head. You start out with a certain amount of life, every time an enemy reaches your base you lose 1 health till you shoot them. I keep score cause later I plan on implementing that into the game as currency. You touch where you want to shoot. I have been looking at LunarView, JetBoyView, CanvasSurfaceView (SpriteMethodTest) files to try and come up with a good canvas structure for the game. I used the bits and pieces I could from all three. The thing that has me a little confused is that in the Jet Boy and Lunar Lander projects the game is done in the Views while with the Sprite Method Test it is split up between the CanvasSurfaceView and CanvasTestActivity. I was wandering as to how I should structure my View file. Should I run everything in my View class or split between the View and Game class.

Current Methods in View:

  • MobView(Context context, AttributeSet attrs)
  • getThread()
  • surfaceChanged
  • SurfaceDestroyed
  • SurfaceCreated
  • onWindowFocusChange
  • MobThread

Methods in Thread: onRun, onPause, onResume, setRunning, setMode, setSurfacesize, MobThread, doDraw, updateGame

I have the Game AI code written is pseudo code till I figure out where I would have to put it at and whether I should use a While loop or If-else statement (it's set up for either one).

share|improve this question
What exactly is your question? GameDev.SE is a question-and-answer based site. What do you want to know? – ashes999 Jun 14 '11 at 11:12

1 Answer 1

Here's a structure I used for some of my Android 2D games with Canvas (before going to OpenGL) :

  • class GameView extends SurfaceView

Mostly handles the touch events and foward them to the GameLogic

  • class GameThread extends Thread

Creates a separate Thread to handle everything GameRelated (you don't want to have your game computations in the main UI thread, to keep the phone reactive even if your game is stuck). The run does the following things :

computeDeltaTime = compute the time since last call, for animations

updateGame = process the user inputs and update all elements in the game

renderGame = renders the game on the Canvas

  • class GameLogic

Handles the game logic, contains the method "updateGame"

  • class GameRenderer

Handles the rendering on the canvas, contains the method "renderGame"

share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.