-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathAnimation.java
More file actions
58 lines (44 loc) · 1.13 KB
/
Animation.java
File metadata and controls
58 lines (44 loc) · 1.13 KB
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
51
52
53
54
55
56
57
58
package com.vinnstar.myfirstgame;
import android.graphics.Bitmap;
/**
* Created by Laurent on 7/6/2016.
*/
public class Animation {
private Bitmap[] frames;
private int currentFrame;
private long startTime;
private long delay;
private boolean playedOnce;
public void setFrames (Bitmap[] frames){
this.frames = frames;
currentFrame = 0;
startTime = System.nanoTime();
}
public void setDelay(long d) {
delay = d;
}
public void setFrame (int i){
currentFrame = i;
}
public void update(){
long elasped = (System.nanoTime() - startTime)/1000000;
if (elasped > delay)
{
currentFrame++;
startTime = System.nanoTime();
}
if (currentFrame == frames.length) {
currentFrame = 0;
playedOnce = true;
}
}
public Bitmap getImage() {
return frames[currentFrame];
}
public int getFrame(){
return currentFrame;
}
public boolean playedOnce() {
return playedOnce;
}
}