Public Group

# c# clearing images

## Recommended Posts

all I want to do is clear a image after I have drawn it, I am able to shoot a bullet and have it hit a bug and draw a collision image then I want to clear the collision image, I know this a simple problem  but I just cant seem to figure it out, thanks for all the help everyone. here is my latest code, I am so close to solving my problem. also please close my previous thread I was told to post a new thread.

        bool draw_flag_coll = true;
int count = 10;
private void Form1_Paint(object sender, PaintEventArgs e)
{
e.Graphics.Clear(Color.Black);
e.Graphics.DrawImage(ship, 350 + x, 530);
e.Graphics.DrawImage(bullet, 375 + x, 520 + y);
e.Graphics.DrawImage(bug_one, 350, 0);
if (y <= -510 && x >= -15 && x <= 15)
{
e.Graphics.DrawImage(coll, 350, 0);
if (count <= 0)
{
draw_flag_coll = false;
}
}
}
private void timer1_Tick(object sender, EventArgs e)
{
y -= 5;
Invalidate();
}
private void timer2_Tick(object sender, EventArgs e)
{
count--;
Invalidate();
}
}

##### Share on other sites

draw_flag_coll is never used

##### Share on other sites

I have almost solved my problem finally, I just need a way to not draw the bug image after I have drawn it. I finally have got the bullet to hit the bug and it then draws the collision image and then draws the  bug a little while later. here is my code.

        int count = 102;
public void Form1_Paint(object sender, PaintEventArgs e)
{
e.Graphics.Clear(Color.Black);
e.Graphics.DrawImage(ship, 350 + x, 530);
e.Graphics.DrawImage(bullet, 375 + x, 520 + y);
e.Graphics.DrawImage(bug_one, 350, 0);
if (y <= -510 && x >= -15 && x <= 15 && count > 0)
{
e.Graphics.DrawImage(coll, 350, 0);
count = 0;
}
}
public void timer1_Tick(object sender, EventArgs e)
{
y -= 5;
Invalidate();
}
public void timer2_Tick(object sender, EventArgs e)
{
count--;
Invalidate();
}

##### Share on other sites

can I please get a little help, I am so close to fixing my problem.

##### Share on other sites

On 3/30/2019 at 7:22 PM, fleabay said:

draw_flag_coll is never used

You don't have to clear an image -- just don't draw it next frame.  You have a boolean flag.  Use that to determine if you want to draw the image or not.

##### Share on other sites

I know this is a dumb response , but how do I not  draw an image?

##### Share on other sites
11 hours ago, phil67rpg said:

but how do I not  draw an image?

The computer only does what you tell it to do. So if you don't tell it to draw an image, it won't.

##### Share on other sites

In programming to "not do something" you use conditions (if statements). If the condition is not met then the code in the curly braces is not done. If the condition is met then code inside the curly braces does get done.

##### Share on other sites
4 hours ago, kseh said:

In programming to "not do something" you use conditions (if statements). If the condition is not met then the code in the curly braces is not done. If the condition is met then code inside the curly braces does get done.

I know how to use if statements, I am just unsure of how to clear the bug once it has been drawn once and after the  collision bitmap is drawn. thanks kseh you have been a lot help. I am also thinking about moving on to a different  project but I am unsure of what to do.

##### Share on other sites

is there any other  project I can do which is a little easier that might  help me with this project?

##### Share on other sites
This topic is now closed to further replies.

• 17
• 19
• 23
• 10
• 10