views:

347

answers:

0

Hi,

I am trying to make an android game. Originally I did not have a separate thread to draw my game on the screen everything worked fine including listening for gestures. But I found that I could not do animation so I have implemented a separate thread that handles drawing my game on the screen. It is based on the Luna Lander example.

This caused my game's graphics to glitch and draw half the level out of place for half a second when I used a gesture detector to listen for scrolls and allow the user to scroll around the screen.

I have had a look at the Luna Lander example. In this example it handles user input and physics in the same thread that does the drawing. I think this is what I have to do to keep the graphics from glitching.

I have an Activity called game. This is the main activity. I have a SurfaceView called MissionView. This is the main view. I have a Thread called GameThread. This is the thread that draws the level on the screen.

Game:

 @Override
 public void onCreate(Bundle savedInstanceState) 
 {
    super.onCreate(savedInstanceState);
    view = new MissionView(this, level);
    setContentView(view);

MissionView:

public MissionView(Context context, Level level)
{
         super(context);
         holder = getHolder();
         holder.addCallback(this);
         thread = new GameThread(holder, this, level);

GameThread:

    public GameThread(SurfaceHolder surfaceHolder, MissionView view, Level level)  
    {
        gestureScanner = new GestureDetector(this);
        this.surfaceHolder = surfaceHolder;
        this.view = view;
        this.level = level;
    }

How do I correctly listen for gestures in the thread? At the moment nothing happens when I make a scroll gesture on the screen.