Delay in a void
in
Programming Questions
•
1 year ago
Hi,
I don't get why this is not working. I know that the delay function is not ideal, but I don't know an alternative...
This is a little bit more complicated. We got a code from our teacher with which we could work. This is what you need to know to understand the code:
rfR is a sprite.
display displays the sprite at a given point (this point is not given in the code below)
hit gets the width and height of playerR and rfR and checks if they overlap.
What doesn't work? The delay function seems to stop the whole program, not just the void. Is this normall?
Heres the simplified code:
- int r2, powerup;
void setup()
{
size(500, 700);
frameRate(5);
r2 = (int)random(8258, 16789);
powerup = powerup = (int)random(7890,19321);
} //end setup
dispRFr = 0; //display rfR when this = 1
spL = 5;
void draw()
{
if(millis()>=r2)
{
dispRFr = 1;
}
if(dispRFr == 1)
{
rfR.display();
if(playerR.hit(rfR))
{
spL += 10;
dispRFr = 0;
rfRwait();
}
}
} //end draw
void rfRwait()
{
delay(powerup);
spL -= 10;
}
Thx for the help
-PStiger
1