1616
1717public 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