Skip to content

Commit 7e4e2c4

Browse files
committed
Fixed sprite fps bug
1 parent c82ebf1 commit 7e4e2c4

File tree

2 files changed

+22
-2
lines changed

2 files changed

+22
-2
lines changed
511 Bytes
Binary file not shown.

src/JavaGameEngine/Components/Sprite/Sprite.java

Lines changed: 22 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616

1717
public class Sprite extends Component {
1818

19-
ArrayList<ArrayList<Rectangle>> animations1 = new ArrayList<>();
19+
ArrayList<BufferedImage[]> animations1 = new ArrayList<>();
2020
public ArrayList<BufferedImage[]> animations = new ArrayList<>();
2121
BufferedImage spriteSheet;
2222
public int animationIndex = 0;
@@ -26,7 +26,24 @@ public class Sprite extends Component {
2626
float angle;
2727

2828
public void setAngle(float angle) {
29-
this.angle = angle;
29+
ArrayList<BufferedImage[]> newAnimations = new ArrayList<>();
30+
for(BufferedImage[] animation : animations1){
31+
BufferedImage[] newAnimation = new BufferedImage[animation.length];
32+
int i = 0;
33+
for(BufferedImage image : animation){
34+
double rotationRequired = Math.toRadians (angle);
35+
double locationX = image.getWidth() / 2;
36+
double locationY = image.getHeight() / 2;
37+
AffineTransform tx = AffineTransform.getRotateInstance(rotationRequired, locationX, locationY);
38+
AffineTransformOp op = new AffineTransformOp(tx, AffineTransformOp.TYPE_BICUBIC);
39+
40+
newAnimation[i] = op.filter(image, null);
41+
i+=1;
42+
}
43+
newAnimations.add(newAnimation);
44+
}
45+
animations = newAnimations;
46+
3047
}
3148

3249
public float getAngle() {
@@ -63,6 +80,7 @@ public void loadAnimation(Rectangle[] tiles,String spriteSheetPath){
6380
i++;
6481
}
6582
animations.add(animation);
83+
animations1.add(animation);
6684
}
6785
/**
6886
* This function loads in sprites from images
@@ -84,6 +102,8 @@ public void loadAnimation(String[] paths){
84102
images[i] = sprite;
85103
}
86104
animations.add(images);
105+
animations1.add(images);
106+
87107
}
88108
/**
89109
* This function loads in all images in side a folder

0 commit comments

Comments
 (0)