Advertisement

c# drawing sprites

Started by March 16, 2019 12:23 AM
55 comments, last by phil67rpg 5 years, 5 months ago

        private void Form1_Paint(object sender, PaintEventArgs e)
        {
            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 == false && y <= -510)
            {
                e.Graphics.DrawImage(coll, 350, 0);
            }
            else if(draw_flag==true)
            {
                e.Graphics.DrawImage(black, 350, 0);
            }
        }
        int count = 0;
        private void timer2_Tick(object sender, EventArgs e)
        {
            if(count %2==0)
            {
                draw_flag = false;
            }
            else
            {
                draw_flag = true;
            }
            count++;
        }

well I have got my code to blink on and  off, it almost does what I want. I have worked on my timer function.

nice work. Check out Brian on youTube. He is using your technology and has some decent things to say.

 

Advertisement

 well I  watched the video and I think I know how to use the timer, I have almost solved my problem I just am unsure of how to get the bug not to blink, according to my code  it looks like it should draw my bug before I draw my collision sprite and   the bug should not blink, I need a fresh pair of eyes to look at my code and see what is wrong.

then don't blink it.

Look at the Brian button link above and check out his collection of instruction.

1 hour ago, GoliathForge said:

then don't blink it.

Look at the Brian button link above and check out his collection of instruction.

how do I get it not to blink? is there any video that might be very helpful?

don't do the odd / even thing with the remainder operator.

Advertisement

I thought this would toggle the values

yes, forever. (I think) we toggle on...we toggle off.

Is something like this what you're looking for?


bool draw_flag = false;
private void Form1_Paint(object sender, PaintEventArgs e)
{
    e.Graphics.Clear(Color.Teal);
    e.Graphics.DrawImage(ship, 350 + x, 530);
    e.Graphics.DrawImage(bullet, 375 + x, 520 + y);
    
    if (draw_flag == false && y <= -510)
    {
        draw_flag = true;
    } else {
        e.Graphics.DrawImage(bug_one, 350, 0);
    }

    if(draw_flag == true)
    {
        e.Graphics.DrawImage(coll, 350, 0);
    }
}

int count = 0;
private void timer2_Tick(object sender, EventArgs e)
{   // is my timer ticking? and when do we enter?
    int someStopValue = 4;
    if(count > someStopValue)
    {
        draw_flag = false;
        count = 0;
        // y = 0; reset somewhere
    }
    
    count++;
}

 

so how do I toggle the values, is there a way that is very proficient? I also googled toggling but did come up anything good

make your own logic. make it how you want. Also I think the google keyword you're after would be animation. 

For instance, check this guy out. It's a little advanced I suspect but the direction you might be interested in.

 

This topic is closed to new replies.

Advertisement