Here’s the important bits of the unit class I use to extend Entity, the init, findPath and the method I use to move. The update method is empty and the render method just draws the sprite at it’s position. For whatever reason it just teleports the unit to the goal, it doesn’t even draw the sprite at the start of the game, just at it’s final location.
public void init(float x, float y) throws SlickException{
Image [] mup = {new Image("data/cv_up_1.png"),new Image("data/cv_up_2.png"),new Image("data/cv_up_3.png"),new Image("data/cv_up_4.png")};
Image [] mdown = {new Image("data/cv_dwn_1.png"),new Image("data/cv_dwn_2.png"),new Image("data/cv_dwn_3.png"),new Image("data/cv_dwn_4.png")};
Image [] mleft = {new Image("data/cv_lft_1.png"),new Image("data/cv_lft_2.png"),new Image("data/cv_lft_3.png")};
Image [] mright = {new Image("data/cv_rt_1.png"),new Image("data/cv_rt_2.png"),new Image("data/cv_rt_3.png")};
Image [] midle = {new Image("data/cv_idle_1.png"),new Image("data/cv_idle_2.png"),new Image("data/cv_idle_3.png")};
initxpos = x;
initypos = y;
xposition = x;
yposition = y;
Tile_Map = new IA_EMBLEM_MAP();
PathFinder = new AStarPathFinder(Tile_Map,100,false, new ManhattanHeuristic(1));
up = new Animation(mup, duration1, true);
down = new Animation(mdown, duration1, true);
left = new Animation(mleft, duration2, true);
right = new Animation(mright, duration2, true);
idle = new Animation(midle, duration2, true);
sprite = idle;
}
public Path findPath(int targetx,int targety){
return PathFinder.findPath(this, (int)initxpos, (int)initypos, targetx, targety);
}
public void move(boolean flag, Path p){
for(int j=0; j<p.getLength();j++){
Log.debug("Step" + j+ ": " + "x: " + p.getStep(j).getX() + " y: " + p.getStep(j).getY());
}
for(int i=1; i<p.getLength();i++){
if(p.getStep(i).getX() > p.getStep(i-1).getX()){
sprite = right;
xposition += 16f;
if(xposition >= xposition +16){
xposition = xposition +16;
}
if(xposition >= 496){
xposition = 496;
}
}
else if(p.getStep(i).getX() < p.getStep(i-1).getX()){
sprite = left;
xposition -= 16f;
if(xposition <= initxpos - 16){
xposition = initxpos - 16;
}
if(xposition <= 0){
xposition = 0;
}
}
else if(p.getStep(i).getY() < p.getStep(i-1).getY()){
sprite = up;
yposition -= 16f;
if(yposition <= 0){
yposition = 0;
}
}
else if(p.getStep(i).getY() > p.getStep(i-1).getY()){
sprite = down;
yposition += 16f;
if(yposition >= 496){
yposition = 496;
}
}
else
{
sprite = idle;
}
}
}
And here’s the play state’s update method:
public void update(GameContainer gc, StateBasedGame sbg, int delta) throws SlickException
{
if (played == false){
played = true;
unit1.move(played, p);
}
}
Any Idea why it could be doing this?