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

2016/12/15

How to pause an Actor

WombatInCombat WombatInCombat

2016/12/15

#
Hey, I´m about to Programm a little game (insted of an exam in computer science). I want my main actor to be able to move straight up and down (trough key-control and setLocation), but i Need to put an delay in there, because he moves with insane Speed. It´s actually looking like this : public void MoveUp() { if (Greenfoot.isKeyDown("up")) { setLocation(getX(), getY() -2); Greenfoot.delay(3); } This works almost how I want it to run, but Greenfoot.delay stops the whole game for a short time - I just want this actor to stop doing anything, so that he moves equably. How to do that ? PS: This program is based on ,,Little Crab"
Super_Hippo Super_Hippo

2016/12/16

#
Try this:
1
2
3
4
5
6
7
8
9
private int delay = 0;
 
public void act()
{
    delay++;
    if (delay < 4) return;
    delay = 0;
    //rest of act method
}
WombatInCombat WombatInCombat

2016/12/18

#
Thanks ! I already solved this Problem before my Question was released to this Forum :)
You need to login to post a reply.