-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathAnimation.java
61 lines (37 loc) · 964 Bytes
/
Animation.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
//package com.game.src.main;
import java.awt.Graphics;
import java.awt.image.BufferedImage;
public class Animation {
private int speed;
private int frames;
private int index = 0;
private int count= 0;
private BufferedImage[] images;
private BufferedImage currentImg;
public Animation (int speed, BufferedImage...args){
this.speed = speed;
images = new BufferedImage[args.length];
for (int i = 0; i < args.length; i++) {
images[i] = args[i];
}
frames = args.length;
}
//repeats animation
public void runAnimation(){
index++;
if (index > speed){
index = 0;
nextFrame();
}
}
private void nextFrame(){
currentImg = images[count%frames];
count++;
}
public void drawAnimation(Graphics g, int x, int y) {
g.drawImage(currentImg, x, y, null);
}
//public void drawAnimation(Graphics g, int x, int y, int scaleX, int scaleY) {
//g.drawImage(currentImg, x, y, scaleX, scaleY, null);
//}
}