Hi everybody, i want to make an actor move on the x-axis 163 steps for- and backwards, but i dont know how to do it.
First i tried it this way:
But every time he reaches the 163 steps Greenfoot crashes. I just want him to move slowly on this line.
Anybody who can help me?
int steps = 0; long lastAdded = System.currentTimeMillis(); public void act() { long curTime = System.currentTimeMillis(); if (curTime >= lastAdded + 5){//5000ms = 5s setLocation(getX()+1, getY()); steps ++; if (schritte == 163){ while (schritte >=0){ if (curTime >= lastAdded + 5){ steps--; setLocation(getX()-1, getY()); lastAdded = curTime; } } } lastAdded = curTime; } }