Hey, I was wondering why my player wasn't moving when press the right or left arrow keys.
Code:
package gamepackage;
import it.marteEngine.entity.*;
import org.newdawn.slick.*;
import org.newdawn.slick.state.*;
public class PlayerFox extends Entity {
public static String PFox = "pfox";
Image foxsheet = new Image("Resources/Fox.png");
Image foxleft = foxsheet.getSubImage(0, 0, 26, 18);
Image foxright = foxsheet.getSubImage(52, 0, 26, 18);
Image[] foxlefta = {foxsheet.getSubImage(0, 0, 26, 18), foxsheet.getSubImage(26, 0, 26, 18)};
Image[] foxrighta = {foxsheet.getSubImage(52, 0, 26, 18), foxsheet.getSubImage(78, 0, 26, 18)};
Animation ismovingleft = new Animation(foxlefta,300,true);
Animation ismovingright = new Animation(foxrighta,300,true);
public PlayerFox(float x, float y) throws SlickException {
super(x, y);
addType(PFox);
setHitBox(0, 0, width, height);
setGraphic(foxright);
}
public void render(GameContainer gc, StateBasedGame sbg, Graphics g) throws SlickException {
super.render(gc, g);
}
public void update(GameContainer gc, StateBasedGame sbg, int delta) throws SlickException, InterruptedException {
super.update(gc, delta);
addAnimation("movingright", ismovingright);
addAnimation("movingleft", ismovingleft);
Input input = gc.getInput();
if(input.isKeyPressed(Input.KEY_RIGHT)) {
x -= (5 * delta);
setAnim("movingright");
}
if(input.isKeyPressed(Input.KEY_LEFT)) {
x += (5 * delta);
setAnim("movingleft");
}
if(input.isKeyPressed(Input.KEY_SPACE)) {
}
}
}