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

2015/4/26

How do you make countdown timer?

Allhard Allhard

2015/4/26

#
Hello there, i got a problem with making a countdown timer. the timer just wont show when i run it. here's the code:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
private int time;
public Play()
    {   
        // Create a new world with 600x400 cells with a cell size of 1x1 pixels.
        super(950,550, 1);
        time = 6000;
        point = 0;
        prepare();
    }
    private void countTime()
    {
        time--;
        showTime();
    }
    private void showTime()
    {
        showText("Time: " + time/100, 50, 50);
    }
Its all in world class. Do I need to make the timer as an actor? or tweaking the method prepare?
danpost danpost

2015/4/26

#
Nothing is calling the 'countTime' method (use an 'act' method for that).
Allhard Allhard

2015/4/26

#
danpost wrote...
Nothing is calling the 'countTime' method (use an 'act' method for that).
it did worked! thanks a lot! but why after i click run, the timer speed seemed to slowed down to half compared to the real time. do u understand? its like when the real time got 2 secs, in this scenario the timer just got 1 sec. any idea?
danpost danpost

2015/4/26

#
You are counting act cycles (which is better from a game-playing perspective -- not real time. Divide time by something line 55 (the approximate number of act cycles per second) for showing the text.
You need to login to post a reply.