c# drawing sprites

Started by
55 comments, last by phil67rpg 5 years ago
16 hours ago, phil67rpg said:

I finished reading my book called C# game programming

Could you give a link on amazon page of this book? I am reading now this book: https://www.amazon.com/Game-Programming-Serious-Creation/dp/1435455568

Advertisement

I have read this book above

simple question: how do I stop drawing a  sprite? here is my reworked code.


        bool draw_flag_coll = false;
        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(draw_flag_coll==true)
            {
                e.Graphics.DrawImage(coll, 350, 0);
            }
        }
        int count = 0;
        private void timer2_Tick(object sender, EventArgs e)
        {
            if (y <= -510 && x >= -15 && x <= 15) 
            {
                draw_flag_coll = true;
                count++;
                if(count == 100)
                {
                    this.Invalidate(true);
                    count = 0;
                }
            }
        }

 

On ‎3‎/‎22‎/‎2019 at 4:23 PM, kseh said:

First, I don't think you want that one call to Invalidate(); inside your paint function.

Second, you don't need to draw a black sprite over your collision sprite and you do not need to erase the collision sprite either. You just need to stop drawing your collision sprite.

If a collision occurs, set a draw flag to true and start counting the number of times you enter the timer function. When that number gets to some value (maybe start with 100 then adjust for duration you want) then set the draw flag to false and reset the count. If the draw flag is set, then draw the collision sprite.

This is the best and simplest advice I can suggest without providing actual code for an example.

Third, I would also like to repeat @GoliathForge's suggestion about keeping notes. I keep a lot of notes in a separate file and I find it useful both in making a plan before I start coding and also when I want to remember why I approached a problem a certain way. I recommend that while you are working, write down what you are doing and why. And find a way to keep your notes organized that makes them the most effective for you.

Good luck on your project.

well I have taken your advice and I have  worked this into my code.

16 hours ago, phil67rpg said:

simple question: how do I stop drawing a  sprite? here is my reworked code.

The answer is:

The same as when you asked how to erase a sprite almost 2 years ago.

The same as when you asked how to erase a character almost 3 years ago.

The same as when you asked how to stop drawing text over 6 years ago.

Hello to all my stalkers.

On 3/24/2019 at 9:28 PM, phil67rpg said:

I have read this book above

But I do not see in your code that you have read this book. The author shows how to work with sprites.

well I think my problem is in  the timer method what I want to do is draw my collision sprite and then after some ticks not draw my collision sprite. 

This topic is closed to new replies.

Advertisement