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

2017/2/7

Changing timer for different levels

pr2alede pr2alede

2017/2/7

#
I have created a game where I've used the Counter in built within greenfoot to create a timer. For level 1 I want the timer to countdown from 2000 then in level 2 I want the timer to count down from 100. I have used and 'if in instance of level 1' set timer value =1000. This does not seem to work. Anyone have any ideas?
Super_Hippo Super_Hippo

2017/2/7

#
You could add the addedToWorld method in the Counter class:
private int timer;

protected void addedToWorld(World w)
{
    if (getWorld() instanceof Level1) timer = 2000;
    else if (getWorld() instanceof Level2) timer = 100;
}
danpost danpost

2017/2/7

#
The Counter class has a 'setValue(int)' method each world can use on its timer to set the appropriate initial value. For example, for the first world:
Counter counter = new Counter("Expiry: ");
counter.setValue(2000);
addObject(counter, 120, 30);
You need to login to post a reply.