Making game when I came across the problem. Wondered if anyone could help me to solve it to make my game better.
int speed = 5;
public void act()
{
move(speed);
checkSlow();
}
public void checkSlow()
{
if(inCertainArea())//here you have to check, if the object is in the area you mean
{
speed=3; //what the speed should be in slow-mode
}
else
{
speed=5;
}
}// using the following declared instance field
private int delayTime = 0;
// in the act method (or in the move method itself, if you have one)
if (delayTime == 0)
{
// code to move actor (or a call to a method to do so, if you have one and not already there)
if (/* inSlowArea */) delayTime = 1; // the speed will be 1/(n+1) normal rate for whatever n you use
} else delayCount--;