Hello everyone and thanks for trying to help me out. I am knee deep in
creating my first android game, and i must say things are going quick
and smooth for the most part! I love this platform and the sdk is
great!
My problem is that I am Drawing to my canvas in a seperate thread,
just like in the lunar lander demo. However when I stop updating the
animations to display the score... well the animations seems to bounce
back and forth between the last 2 frames! so while the score
information is displayed on top clearly, the background is all jiggly.
The code is long and messy so I will try to reproduce it here more
clearly.
DoDraw(Surface surface){
if (state == "showscore"){
surface.drawText(.....)
}
if (state== "go"){
canvas.drawBitmap(0,0,arenabackground)
animate();
drawstuff();
}
}
Thats a really simplistic view of things but i will post the full code
at the end. So when i run this everything works fine except that
during the time period that state=="showscore" the things that are
animated are bouncing back and forth presumibly because the canvas is
bouncing back and forth between the last 2 frames..here is the code:
private void doDraw(Canvas canvas) {
long st = System.nanoTime();
long et;
if (state == "showscore"){
if (score_show_end_time==0){
canvas.save();
}
canvas.drawText(String.valueOf(score1)+ " to " +String.valueOf
(score2),(float)(screen_width/2)-75,(float)screen_height/
2,paint_score2);
canvas.restore();
if (System.nanoTime()>score_show_end_time){
state = "go";
score_show_end_time=0;
restart();
}
}
if (state == "go"){
canvas.drawBitmap(image_arena, 0, 0, null);
bomb_physx();
if (handle_x < 60){handle_x = 60;}
if (handle_x > screen_width-60){handle_x =
screen_width-60;}
int dif = (int) (handle_x-ship1.x);
if (dif>1){ship1.goright(dif);}
if (dif<-1){ship1.goleft(dif);}
if ((dif>-1)&&(dif<1)){ship1.stopx();}
handle_normal.setBounds((int) (int)handle_x-60,
(int)
handle_y-40, (int)handle_x+60,(int)handle_y+40);
handle_normal.draw(canvas);
ship1.update();
ship1.draw(canvas);
ship_ai(ship2,70);
ship2.update();
ship2.draw(canvas);
bomb_image1.setBounds((int) (int)x-bomb_offsetx,
(int)y-
bomb_offsety, (int)x+bomb_offsetx,(int)y+bomb_offsety);
bomb_image1.draw(canvas);
et = System.nanoTime()-st;
canvas.drawText(String.valueOf(et*.000000001),(float)10,(float)
50,paint_line1);
}
}
--
You received this message because you are subscribed to the Google
Groups "Android Beginners" group.
NEW! Try asking and tagging your question on Stack Overflow at
http://stackoverflow.com/questions/tagged/android
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/android-beginners?hl=en