views:

155

answers:

1

I've never built a game before, and I've not programmed for Android before but am looking to do so over the summer by building a game.

What type of object do I use for a shape that I want the user to be able to drag around the screen for instance using touch gestures? How do I tie together the MotionEvent, View and Graphics2D to make objects drawn on screen that can be interacted with? I imagine this will use ActionListeners / Handlers but I'm a bit confused at this stage...

A simple breakdown of steps would be much appreciated. Thanks

+1  A: 

This is quite a broad question! :P Basically, here is what you want to do:

  1. Use a drawing canvas as part of a custom view. This View should extends SurfaceView implements SurfaceHolder.Callback
  2. The OnTouchEvent(MotionEvent event) is the callback when the user touches the screen
  3. You can redraw your canvas elements based on the position of the touch gestures, as retrieved from OnTouchEvent

An excellent source of basic information about 2D games is the LunarLander example that comes with the SDK. It demonstrates how to make a custom view and canvas, how to multithread for continuous animation and how to handle the game state as the user switches to another app.

I've also answered lots of questions about graphics which may be helpful for you to look at. You can find a list of links here.

Steve H
Thank you very much. It is much appreciated, I will look into that example and your other answers. Its a more approachable platform than iPhone to me as I dont know cocoa really.
Greenhouse_Gases