Remove bitmap from canvas drawBitmap in Android Java

Viewed 46

I'm currently build a flappy bird app and I want to implement the coin between pipes. The coins are successfully placed between the pipes. The problem is, when the bird hitting the coin, the coin should be gone. What should I do to make the coin gone? Any help would be appreciated, thank you!

GameEngine.java

public void updateAndDrawTubes(Canvas canvas) {
     for (int i = 0; i < AppConstants.numberOfTubes; i++) {
            coinX = coin.getCoinX() + 55;
            coinY = tubes.get(i).getTopTubeOffsetY() + 150;

            // draw top tube
            canvas.drawBitmap(AppConstants.getBitmapBank().getTubeTop(), tubes.get(i).getTubeX(), tubes.get(i).getTopTubeY(), null);

            // draw coin between tubes/pipes
            canvas.drawBitmap(AppConstants.getBitmapBank().getCoin(), coinX, coinY, null);
            
            // draw bottom tube
            canvas.drawBitmap(AppConstants.getBitmapBank().getTubeBottom(), tubes.get(i).getTubeX(), tubes.get(i).getBottomTubeY(), null);
     }
}
1 Answers

The only way is calling canvas.invalidate() to re-draw canvas, then handle logic to draw bitmap or not - example:

if(your_logic())
{
    // draw bitmap as you want
    canvas.drawBitmap(AppConstants.getBitmapBank().getTubeTop(), tubes.get(i).getTubeX(), tubes.get(i).getTopTubeY(), null);
    
}
else{
  // do nothing 
}
Related