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

2021/11/4

timer code

siizwee siizwee

2021/11/4

#
please how can i write a code for an actor to change colour after a few seconds, dont know how the timer works
danpost danpost

2021/11/4

#
siizwee wrote...
please how can i write a code for an actor to change colour after a few seconds, dont know how the timer works
You only need a timer field:
private int colourTimer;

public void act()
{
    if (colourTimer < 150 && ++colourTimer == 150) changeColour();
}
You can then add a changeColour method which does the actual changing of the colour or you can replace that method call on line 5 with a block of code that does it right there.
siizwee siizwee

2021/11/5

#
do i have to initialise the simpleTime class?
danpost danpost

2021/11/5

#
siizwee wrote...
do i have to initialise the simpleTime class?
You don't need that class unless you want the timer to be shown on the screen.
You need to login to post a reply.