you are exactly correct
c# drawing sprites
Looking at the last code you posted, I do see everything there that I suggested but just not quite as I had intended. I was thinking something more like below.
private void timer2_Tick(object sender, EventArgs e)
{
if (y <= -510 && x >= -15 && x <= 15)
{
draw_flag_coll = true;
count=0;
}
if(draw_flag_coll==true)
{
count++;
if(count >= 100)
{
draw_flag_coll=false;
}
}
this.Invalidate(true);
}
Phil, if you understand what's going on in the above code, I'm wondering if you would please describe to us in your own words how you understand it.
well kseh your code looks like it works, but it does not, it only draws the collision sprite, I am wondering if the problem is in my paint method. here is my current 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 = 0;
}
if (draw_flag_coll == true)
{
count++;
if (count >= 100)
{
draw_flag_coll = false;
}
}
this.Invalidate(true);
}
}
well it draws the collision sprite and then after a period of time it draws a bug and then the collision sprite again.
On 3/26/2019 at 5:13 PM, Daniel Ricci said:Okay, so then do that.
1. Detect when there is a collision
2. When a collision occurs call a method that will count down `x` seconds
3. When `x` seconds has been reached, set the flag to false to prevent it from being drawn.
This is a 10 minute fix.
well I coded up the above suggestion, let me know if I am on the right track, also I read the debugger link several times and have worked with my code setting breakpoints and step into and step over features. it is very interesting, here is my code for the above suggestion.
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();
}