Before I say anything, here's my code for you to reference back to:
So, I was making a game, and wanted to display text but with delays in between. I didn't want to use wait(5); or anything similar.
I wanted to count system time in ms, and use a function to wait in just that actor, but it's not letting me do
I'm used to python, making new functions with the arguements in parentheses...
I only made 1 project in Greenfoot, so I don't know much about this kind of stuff.
import greenfoot.*;
import java.awt.Color;
/**
* Write a description of class Explains here.
*
* @author (your name)
* @version (a version number or a date)
*/
public class Explains extends Actor
{
long lastTime = System.currentTimeMillis();
/**
* Act - do whatever the Explains wants to do. This method is called whenever
* the 'Act' or 'Run' button gets pressed in the environment.
*/
public void act()
{
text();
start();
}
public void wait(w);
{
long cTime = System.currentTimeMillis();
if (cTime >= lastTime + w) //5000ms = 5s
{
lastTime = cTime;
}
}
public void text()
{
setImage(new GreenfootImage("DETECTIVE", 24, Color.RED, Color.WHITE));
wait(2500);
}
public void start()
{
}
}
public void wait(w);
