I'm learning to create an Android shooter game where I'll have multiple enemies. I must control the position on the screen and be able to delete each of then (via, for example, a die() function).

But I use a canvas, which is most recomended, is it possible to delete just one bitmap and not the entire canvas (by delete I mean make it vanish from the screen, not just erase its value)? If so, how?

Another approach, I guess, would be using the Android image view, which can be deleted and as well as controlled and positioned, but I think that can make my game run slow if I create various objects of a class enemy; is that correct?


1 Answer 1


This sounds a bit like you've got a basic design error in your game.

When displaying scenes on the screen, games typically follow the following pattern:

  • Delete the screen
  • Draw everything
  • Display the screen

Thanks to double buffering, this isn't as noticeable as you might think (i.e. there's no flickering).

So what you'd have to do is the following:

  • Clear the screen. Based on how you draw the game, you might be able to skip this step.
  • Draw the background.
  • Draw all characters (whether they're spaceships, mushrooms, or whatever)
  • Present the screen (i.e. swap buffers).

The whole process also varies slightly based on the actual drawing technology you're using (e.g. Canvas vs. OpenGL ES). In either way, you should only draw to one big screen. Don't try to draw everything into its own canvas element or anything like that.

  • \$\begingroup\$ How do you mean "clear the screen"? In my android game I use canvas and if I were to remove my background then every sprite would leave a "pattern" of sprites from the last frames, are you saying its not supposed to be like that? Because I havent run in to any problems doing this. But ur saying the canvas should be cleared? Do you mean at the start of each frame or at the end of each frame? \$\endgroup\$
    – Green_qaue
    Commented Feb 14, 2014 at 12:41
  • \$\begingroup\$ @iQue, something like: while(gameRunning){ canvas.drawColor(black); for(Enemy enemy : enemies){ enemy.draw(canvas); } logic(); } \$\endgroup\$ Commented Feb 14, 2014 at 19:47
  • \$\begingroup\$ Oh so basically just drawing a Bg over the last frames sprites. Okey \$\endgroup\$
    – Green_qaue
    Commented Feb 14, 2014 at 19:56
  • \$\begingroup\$ Thank you. That was my question. If I really have to redo all draws all the time. \$\endgroup\$ Commented Feb 14, 2014 at 21:20
  • \$\begingroup\$ @iQue: Yes, traditionally, you'd clear the screen with a solid color. But if you're drawing solid background anyway, you can skip that step to save some processing time. \$\endgroup\$
    – Mario
    Commented Feb 14, 2014 at 22:32

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .