hey guys--
I am just getting started with some game development here and was
messing around with some examples i found and some of the lunar lander
stuff. but I am having trouble on updating the location of the bitmap
(lander). its actually working but on my action move event after i
update the x and y for the lander i have to call invalidate(); to
force the refresh and i am curious why i have to do that? i thought
when you created a surfaceview with a holder call back that it always
called ondraw durring the running state.. here is the motion and draw
code... the lander is in its own class and like i said this does work
but i am just trying to figure it out...
public boolean onTouchEvent(MotionEvent event)
{
//Log.d("Panel","Surface touched");
if (event.getAction() == MotionEvent.ACTION_DOWN)
{
// delegating event handling to the lander
Log.d("Action Event","ACTION DOWN");
lander.handleActionDown((int)event.getX(),
(int)event.getY());
// check if in the lower part of the screen we exit
//if (event.getY() > getHeight() - 50)
//{
// thread.setRunning(false);
// ((Activity)getContext()).finish();
//}
//else
//{
//}
}
if (event.getAction() == MotionEvent.ACTION_MOVE)
{
// the gestures
Log.d("Action Event","ACTION MOVE");
if (lander.isTouched())
{
Log.d("Action Event","ACTION MOVE is Touched");
// the lander was picked up and is being dragged
lander.setX((int)event.getX());
lander.setY((int)event.getY());
invalidate(); //THIS WORKS
}
}
if (event.getAction() == MotionEvent.ACTION_UP)
{
// touch was released
if (lander.isTouched())
{
lander.setTouched(false);
}
}
return true;
//return super.onTouchEvent(event);
}
@Override
protected void onDraw(Canvas canvas)
{
lander.draw(canvas);
}
here is my run loop
public void run() {
Canvas canvas;
long tickcount = 0L;
Log.d(TAG, "Starting game loop");
while (running)
{
tickcount++;
canvas = null;
// try locking the canvas for exclusive pixel
editing on the
surface
try
{
canvas =
this.surfaceHolder.lockCanvas();
synchronized (surfaceHolder)
{
// update game state
// draws the canvas on the panel
this.gamePanel.onDraw(canvas);
}
}
finally
{
// in case of an exception the surface
is not left in
// an inconsistent state
if (canvas != null)
{
surfaceHolder.unlockCanvasAndPost(canvas);
}
} // end finally
}
Log.d(TAG, "Game loop executed " + tickcount + "
times");
}
thank you all for the info... so far so good and getting a handle on
it...
--
You received this message because you are subscribed to the Google
Groups "Android Developers" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en