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

2021/9/4

I NEED HELP

Tuffel Tuffel

2021/9/4

#
i have Greenfoot at school and we got a precoded file with some actors. But when im writing in one actor "Greenfoot.delay(100)", the other actors will stop too. Can someone explain this to me and give me a solution how to make only one actor stop?
danpost danpost

2021/9/4

#
Tuffel wrote...
im writing in one actor "Greenfoot.delay(100)", the other actors will stop too. Can someone explain this to me and give me a solution how to make only one actor stop?
The Greenfoot.delay(int numberOfActCyclesToPause) method will delay the running of the scenario by the given value, skipping that number of full act cycles. If you only want one actor to pause, then add an int field to count down the act cycles being skipped:
int pauseTimer;

public void act()
{
    if (pauseTimer > 0 && --pauseTimer > 0) return;
    // action codes here
}
Somewhere in your codes (not necessarily in the same class -- but usually will be found there), you would have (in pseudo-code):
if (some_condition(s) == true) pausing_actor.pauseTimer = numberOfActCyclesToPause;
to initiate the pausing of the actor
Tuffel Tuffel

2021/9/4

#
So how do i now slow it down?
danpost danpost

2021/9/4

#
Tuffel wrote...
So how do i now slow it down?
Add int field for slow down amount (higher value, longer pause):
int pauseTimer;
int slowDown;

public void act()
{
    if (pauseTimer > 0 && --pauseTimer > 0) return;
    if (pauseTimer == 0) pauseTimer = slowDown+1;
    // action code here
}
Somewhere in codes should be control of slowDown value (pseudo-code):
if (someCondition) pauseActor.slowDown++; // increase slow down
if (someOtherCondition && pauseActor.slowDown > 0) pauseActor.slowDown--; // decrease slow down
You need to login to post a reply.