Collisions and animation updates working

master
Jonathan Hager 5 years ago
commit 25453d2cf6

@ -45,19 +45,6 @@ public class AnimatedSprite {
}
}
/*
public void updateBackwards(){
if(getFrame() <= 0){
setFrame(texture[0].length - 1);
}
else{
setFrame(getFrame() - 1);
}
sprite.setRegion(texture[getRow()][getFrame()]);
}
*/
public void draw(Batch batch) {
sprite.draw(batch);
}

@ -27,6 +27,8 @@ public class Player extends Actor{
float movementX = 0;
float movementY = 0;
float speed = 2f;
// 0: up, 1: left, 2: down, 3: right
int facing = 0;
public Player(int xPos, int yPos){
@ -49,15 +51,19 @@ public class Player extends Actor{
public void act(float delta) {
if(Gdx.input.isKeyPressed(Input.Keys.D)){
movementX = speed;
facing = 3;
}
if(Gdx.input.isKeyPressed(Input.Keys.A)){
movementX = -speed;
facing = 1;
}
if(Gdx.input.isKeyPressed(Input.Keys.W)){
movementY = speed;
facing = 0;
}
if(Gdx.input.isKeyPressed(Input.Keys.S)){
movementY = -speed;
facing = 2;
}
/**
* return
@ -81,12 +87,20 @@ public class Player extends Actor{
case 3:
break;
}
int animationRow = 0;
if(movementX != 0 || movementY != 0) {
animationRow = 8;
}
playerSprite.setRow(animationRow + facing);
movementX = 0;
movementY = 0;
playerSprite.updateAnimation(delta);
super.act(delta); //To change body of generated methods, choose Tools | Templates.
}
@Override
@ -155,5 +169,4 @@ public class Player extends Actor{
return 3;
}
}

Loading…
Cancel
Save