Michael Zeuner
Michael Zeuner

Reputation: 1776

Removing bitmaps in android

How do you remove a Bitmap in android? I have created a bitmap that is called"sun" but as soon as I have finished a guy walking across the screen I want to add a new bit map called "moon" but it just gets created over top of the sun, how can I remove the sun bitmap? here is my code for the walking guy.

    switch (counter)
    {

    case 0:
        skyRect.set(0, 0, canvas.getWidth(), 400);
        canvas.drawRect(skyRect, sky);
        canvas.drawBitmap(AndroidDude, changingX, (canvas.getHeight()/2 - (AndroidDude.getHeight()/2)), null);
        if (changingX < canvas.getWidth())
        {
            changingX += 10;
        }
        else 
        {
            changingX = 0;
            sunChangingX = 0;
            counter++;
        }

        grassRect.set(0, 400, canvas.getWidth(), canvas.getHeight());
        canvas.drawRect(grassRect, grass);
        canvas.drawBitmap(cloud, 100, 50, null);
        canvas.drawBitmap(cloud, 700, 100, null);
        canvas.drawBitmap(sun, (canvas.getWidth() - sun.getWidth()), 0, null);
        invalidate();
        break;

    case 1:
        //Remove sun and clouds here?
        canvas.drawBitmap(moon, (canvas.getWidth() - moon.getWidth()), 0, null);
        canvas.drawBitmap(AndroidDude, changingX, (canvas.getHeight()/2 - (AndroidDude.getHeight()/2)), null);
        if (changingX < canvas.getWidth())
        {
            changingX += 10;
        }
        else 
        {
            changingX = 0;
            counter++;
        }
        grassRect.set(0, 400, canvas.getWidth(), canvas.getHeight());
        canvas.drawRect(grassRect, grass);
        canvas.drawBitmap(cloud, 100, 50, null);
        canvas.drawBitmap(cloud, 700, 100, null);
        canvas.drawBitmap(sun, sunChangingX, 0, null);
        invalidate();
        break;
    }

Upvotes: 0

Views: 2707

Answers (3)

MAC
MAC

Reputation: 15847

Canvas.drawColor(Color.WHITE);

or

You can have to clean canvas so you can draw rectangle with WHITE color.

// or whatever your canvas color

It will looks like canvas is blank.

and again draw what ever you want.

your output will display on white color.

Upvotes: 0

toto2
toto2

Reputation: 5326

You just draw new things over the old ones. If you need to "erase" something, you just redraw the background.

Upvotes: 0

Kickaha
Kickaha

Reputation: 3857

Redraw your background (sky and grass) over the bitmap you want removed. Make a refresh function.

Upvotes: 1

Related Questions