🎉 Celebrating 25 Years of GameDev.net! 🎉

Not many can claim 25 years on the Internet! Join us in celebrating this milestone. Learn more about our history, and thank you for being a part of our community!

c# clearing images

Started by
53 comments, last by phil67rpg 5 years, 2 months ago

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();
        }
    }

 

Advertisement

draw_flag_coll is never used

🙂🙂🙂🙂🙂<←The tone posse, ready for action.

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();
        }

 

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

 

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.

"The code you write when you learn a new language is shit.
You either already know that and you are wise, or you don’t realize it for many years and you are an idiot. Either way, your learning code is objectively shit." - L. Spiro

"This is called programming. The art of typing shit into an editor/IDE is not programming, it's basically data entry. The part that makes a programmer a programmer is their problem solving skills." - Serapth

"The 'friend' relationship in c++ is the tightest coupling you can give two objects. Friends can reach out and touch your privates." - frob

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

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.

🙂🙂🙂🙂🙂<←The tone posse, ready for action.

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.

This topic is closed to new replies.

Advertisement