This site requires JavaScript, please enable it in your browser!
Greenfoot back
Sk1llG4m3r
Sk1llG4m3r wrote ...

2016/10/28

I need help with delay/wait

Sk1llG4m3r Sk1llG4m3r

2016/10/28

#
i want that if the actor hits an object that just the actor freezes for 1 second but i dont know how to do this Please help me :D
danpost danpost

2016/10/28

#
Sk1llG4m3r wrote...
i want that if the actor hits an object that just the actor freezes for 1 second
Add an instance int field to the class to count down the act cycles it is to be frozen for. For each execution of the act method, if the value of the field is zero, then the actor is not frozen (act normally); if it is not zero, decrement its value. When it hits the object in question, set the value of the field to something around 50, or 60. This would look something like the following:
// with instance field
private int freezeTimeRemaining;

// at beginning of act method
if (freezeTimeRemaining != 0 && --freezeTimeRemaining != 0) return;

// elsewhere in act method (or a method called by it)
if (isTouching(Icing.class)) // adjust class name as needed
{
    freezeTimeRemaining = 55;
}
You need to login to post a reply.