Line | |
---|
1 | package gamegui;
|
---|
2 |
|
---|
3 | import java.awt.*;
|
---|
4 | import java.awt.image.*;
|
---|
5 | import java.util.*;
|
---|
6 |
|
---|
7 | public class Animation extends Member
|
---|
8 | {
|
---|
9 | ArrayList<BufferedImage> frames;
|
---|
10 | int currentFrame;
|
---|
11 | int drawInterval;
|
---|
12 | long lastFrameChange;
|
---|
13 |
|
---|
14 | public Animation(String newName, int newX, int newY, int newWidth, int newHeight, int newInterval)
|
---|
15 | {
|
---|
16 | super(newName, newX, newY, newWidth, newHeight);
|
---|
17 |
|
---|
18 | frames = new ArrayList<BufferedImage>();
|
---|
19 | currentFrame = 0;
|
---|
20 | drawInterval = newInterval;
|
---|
21 | lastFrameChange = 0;
|
---|
22 | }
|
---|
23 |
|
---|
24 | public void addFrame(BufferedImage newFrame)
|
---|
25 | {
|
---|
26 | frames.add(newFrame);
|
---|
27 | }
|
---|
28 |
|
---|
29 | public void draw(Graphics g)
|
---|
30 | {
|
---|
31 | if(System.currentTimeMillis() - lastFrameChange > drawInterval)
|
---|
32 | {
|
---|
33 | currentFrame++;
|
---|
34 | if(currentFrame >= frames.size())
|
---|
35 | currentFrame = 0;
|
---|
36 |
|
---|
37 | lastFrameChange = System.currentTimeMillis();
|
---|
38 | }
|
---|
39 |
|
---|
40 | g.drawImage(frames.get(currentFrame), getX(), getY(), null);
|
---|
41 | }
|
---|
42 | }
|
---|
Note:
See
TracBrowser
for help on using the repository browser.