source: lost-haven/gamegui/Animation.java@ a5b4186

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

[svn r36] Renamed remotely

  • Property mode set to 100644
File size: 930 bytes
Line 
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.