Revision 4535,
1.6 KB
checked in by dezhidki, 10 years ago
(diff) |
Uusi versio:
- Tason luonti valmis
- Piirtojärjestys toimii
- Palikoiden lisääminen ja muokkaus toimii
- Esivalmistelut liikkumista varten
|
Line | |
---|
1 | |
---|
2 | namespace CastleMaster.Graphics |
---|
3 | { |
---|
4 | public class AnimationHelper |
---|
5 | { |
---|
6 | private int currentFrame, minFrame, maxFrame, currentTicks, ticksPerFrame; |
---|
7 | private bool isRunning = false, runOnce; |
---|
8 | |
---|
9 | public AnimationHelper(int ticksPerFrame, int maxFrame, bool runOnce = false, int minFrame = 0, int currentFrame = 0) |
---|
10 | { |
---|
11 | this.ticksPerFrame = ticksPerFrame; |
---|
12 | this.maxFrame = maxFrame; |
---|
13 | this.minFrame = minFrame; |
---|
14 | this.currentFrame = currentFrame < minFrame ? minFrame : currentFrame; |
---|
15 | this.runOnce = runOnce; |
---|
16 | currentTicks = 0; |
---|
17 | } |
---|
18 | |
---|
19 | public int CurrentFrame { get { return currentFrame; } } |
---|
20 | |
---|
21 | public AnimationHelper Start() |
---|
22 | { |
---|
23 | if (!isRunning) |
---|
24 | isRunning = true; |
---|
25 | return this; |
---|
26 | } |
---|
27 | |
---|
28 | public void Stop() |
---|
29 | { |
---|
30 | isRunning = false; |
---|
31 | } |
---|
32 | |
---|
33 | public void Reset() |
---|
34 | { |
---|
35 | currentFrame = minFrame; |
---|
36 | currentTicks = 0; |
---|
37 | } |
---|
38 | |
---|
39 | public void Restart() |
---|
40 | { |
---|
41 | isRunning = true; |
---|
42 | currentFrame = minFrame; |
---|
43 | currentTicks = 0; |
---|
44 | } |
---|
45 | |
---|
46 | public void UpdateStep() |
---|
47 | { |
---|
48 | currentTicks++; |
---|
49 | |
---|
50 | if (currentTicks > ticksPerFrame) |
---|
51 | { |
---|
52 | currentFrame++; |
---|
53 | if (currentFrame > maxFrame) |
---|
54 | { |
---|
55 | if (runOnce) Stop(); |
---|
56 | else currentFrame = 0; |
---|
57 | } |
---|
58 | |
---|
59 | currentTicks = 0; |
---|
60 | } |
---|
61 | } |
---|
62 | } |
---|
63 | } |
---|
Note: See
TracBrowser
for help on using the repository browser.