I'm trying to get a character to move between two points only (a bit like a victory pose), I have this:
But when if it continues running the character slowly moves down further then it should. Any ideas?
import greenfoot.*; // (World, Actor, GreenfootImage, Greenfoot and MouseInfo)
/**
* Write a description of class Toad here.
*
* @author (your name)
* @version (a version number or a date)
*/
public class Toad extends ScrollingActor
{
protected static final GreenfootImage Toad = new GreenfootImage("toad.gif");
public Toad()
{
shared.speed = 1;
shared.animationDelay = 50;
setImage(Toad);
Toad.scale(23,35);
}
/**
* Act - do whatever the Toad wants to do. This method is called whenever
* the 'Act' or 'Run' button gets pressed in the environment.
*/
public void act()
{
moveUpDown();
}
private void moveUpDown()
{
shared.frame ++;
if(shared.frame < 1 * shared.animationDelay)
{
shared.moveUp(this);
}
else if(shared.frame < 2 * shared.animationDelay)
{
shared.moveDown(this);
}
if(shared.frame > 2 * shared.animationDelay)
{
shared.frame = 0;
}
}
}
