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

2015/5/8

Hello, i want to make a countdown timer

Srax Srax

2015/5/8

#
Can anyone help me make a simple timer, that can count down from 1 minute? and after 1 mute, the world should reset. Thanks in advance.
Super_Hippo Super_Hippo

2015/5/8

#
Simply add the timer the world class.
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
private int time = 0;
 
public WorldName()
{
    super(/**...*/);
    Greenfoot.setSpeed(50);
    prepare();
}
 
private void prepare()
{
    time = 3300;
    //adding objects here
}
 
public void act()
{
    time--;
    if (time == 0)
    {
        removeObjects(getObjects(null));
        prepare();
        /** OR **/
        Greenfoot.setWorld(new WorldName());
    }
}
Srax Srax

2015/5/8

#
Super_Hippo wrote...
Simply add the timer the world class.
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
private int time = 0;
 
public WorldName()
{
    super(/**...*/);
    Greenfoot.setSpeed(50);
    prepare();
}
 
private void prepare()
{
    time = 3300;
    //adding objects here
}
 
public void act()
{
    time--;
    if (time == 0)
    {
        removeObjects(getObjects(null));
        prepare();
        /** OR **/
        Greenfoot.setWorld(new WorldName());
    }
}
Thank you very much :)
You need to login to post a reply.