Hello, my English is not very good and I am a beginner with Greenfoot. I have an actor with different Images (to simulate real moving) who can move 1 pixel on a map (circa 640x640 pixels). But moving only 1 pixel is too slow. When I set the speed up the Images (to simulate real moving) are changing to fast. The actor must move only 1 pixel because he must stop shortly before a barrier (not 2,3,4,5,... pixels before the barrier).
This is my code:
I hope you can help me.
private GreenfootImage ao1 = new GreenfootImage("ao1.png");
private GreenfootImage ao2 = new GreenfootImage("ao2.png");
private GreenfootImage ao3 = new GreenfootImage("ao3.png");
private GreenfootImage ao4 = new GreenfootImage("ao4.png");
private GreenfootImage ao5 = new GreenfootImage("ao5.png");
private GreenfootImage ao6 = new GreenfootImage("ao6.png");
private int frameArR = 1;
public boolean wandRechts()
{
return getOneObjectAtOffset(35, 0,Stein.class) != null;
}
public void RechtsBewegung()
{
if(frameArR == 1)
{
setImage(ao1);
}
else if(frameArR == 2)
{
setImage(ao2);
}
else if(frameArR == 3)
{
setImage(ao3);
}
else if(frameArR < 4)
{
setImage(ao4);
}
else if(frameArR < 5)
{
setImage(ao5);
}
else if(frameArR == 6)
{
setImage(ao6);
if(frameArR == 6)
{
frameArR = 1;
}
return;
}
frameArR = frameArR + 1;
public void act()
{
if(Greenfoot.isKeyDown("right"))
{
RechtsBewegung();
if(!wandRechts())
{
move(5);
}
}
}
