source: java-rpg-client/gamegui/Animation.java

Last change on this file was 55522be, checked in by dportnoy <dmp1488@…>, 17 years ago

[svn r8]

  • Property mode set to 100644
File size: 930 bytes
RevLine 
[55522be]1package gamegui;
2
3import java.awt.*;
4import java.awt.image.*;
5import java.util.*;
6
7public 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.