Skip to content

Commit

Permalink
Updated sprite animation - now full works.
Browse files Browse the repository at this point in the history
Updated actor class - wrong sprite.update parameters
  • Loading branch information
thoniorf committed Sep 8, 2015
1 parent babeae9 commit ecb7e8f
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 16 deletions.
30 changes: 15 additions & 15 deletions src/it/batteringvalhalla/gamecore/animation/Sprite.java
Original file line number Diff line number Diff line change
Expand Up @@ -56,25 +56,25 @@ public Sprite(Image img, Integer imageWidth, Integer imageHeight,
framesPerRow = new Integer(imageWidth / frameWidth);
}

public void update(float speedx, float speedy) {

currentFrame = (currentFrame + 1) % endFrame;
counter = (counter + 1) % frameSpeed;
frameCol = currentFrame % framesPerRow;
frameRow = currentFrame / framesPerRow;

public void update(Direction dir) {
if (!(dir == Direction.stop && currentFrame == 1)) {
currentFrame = (currentFrame + 1) % endFrame;
counter = (counter + 1) % frameSpeed;
frameCol = currentFrame % framesPerRow;
frameRow = currentFrame / framesPerRow;
}
g2 = (Graphics2D) frame.getGraphics();
g2.drawImage(img.getSubimage(frameCol * frameWidth, frameRow
* frameHeight, frameWidth, frameHeight), 0, 0, null);
g2.dispose();
// if (dir != imgDir && dir != Direction.stop) {
AffineTransform tx = AffineTransform.getScaleInstance(-1, 1);
tx.translate(-frame.getWidth(null), 0);
AffineTransformOp op = new AffineTransformOp(tx,
AffineTransformOp.TYPE_NEAREST_NEIGHBOR);
frame = op.filter(frame, null);
// imgDir = dir;
// }
if (dir == Direction.ovest || imgDir == Direction.ovest) {
AffineTransform tx = AffineTransform.getScaleInstance(-1, 1);
tx.translate(-frame.getWidth(null), 0);
AffineTransformOp op = new AffineTransformOp(tx,
AffineTransformOp.TYPE_NEAREST_NEIGHBOR);
frame = op.filter(frame, null);
imgDir = (dir != Direction.stop) ? dir : imgDir;
}
}

public BufferedImage getFrame() {
Expand Down
2 changes: 1 addition & 1 deletion src/it/batteringvalhalla/gamecore/object/actor/Actor.java
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ public void incrementLive() {
@Override
public void update() {
super.update();
sprite.update(speedX,speedY);
sprite.update(direction);
};

@Override
Expand Down

0 comments on commit ecb7e8f

Please sign in to comment.