Web   ·   Wiki   ·   Activities   ·   Blog   ·   Lists   ·   Chat   ·   Meeting   ·   Bugs   ·   Git   ·   Translate   ·   Archive   ·   People   ·   Donate
summaryrefslogtreecommitdiffstats
path: root/src/api/Anim.py
blob: 2310f5ef2a5f790a5a96679c1632239eaece8670 (plain)
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
59
60
61
62
63
64
65
66
67
68
# -*- coding: utf-8 -*-


class CAnim(object):

    mNumFrames = 0
    mDelay = 0
    mCurrentFrame = 0
    mTimeFrame = 0
    mIsLoop = False
    
    # Flag to indicate it the animation has ended.
    mEnded = False

    # Indicates if frame has changed since the previous update().
    mFrameHasChanged = False

    # Used to calculate if the previous frame is the same as the current frame.
    mPreviousFrame = 0
    
    mMinFrame = 0

    def __init__(self, aNumFrames, aDelay, aIsLoop = False):
        self.init(aNumFrames, aDelay, aIsLoop);
       
    def init(self, aNumFrames, aDelay, aIsLoop = False, aMinFrame = 0):
        self.mNumFrames = aNumFrames
        self.mDelay = aDelay
        self.mCurrentFrame = aMinFrame
        self.mTimeFrame = 0
        self.mIsLoop = aIsLoop
        self.mEnded = False
        self.mFrameHasChanged = False
        self.mPreviousFrame = 0
        self.mMinFrame = aMinFrame
    
    def reset(self):
        self.mCurrentFrame = 0
        self.mTimeFrame = 0
        self.mFrameHasChanged = False
        self.mPreviousFrame = 0
        
    def update(self):
        self.mTimeFrame += 1
        if (self.mTimeFrame >= self.mDelay):
            self.mTimeFrame = 0
            self.mCurrentFrame += 1
            if (self.mCurrentFrame >= self.mNumFrames):
                if (self.mIsLoop):
                    self.mCurrentFrame = self.mMinFrame
                else:
                    self.mCurrentFrame = self.mNumFrames - 1
                    self.mEnded = True
                    
        if (self.mPreviousFrame <> self.mCurrentFrame):
            self.mFrameHasChanged = True
        else:
            self.mFrameHasChanged = False            
        self.mPreviousFrame = self.mCurrentFrame
        
    def getCurrentFrame(self):
        return self.mCurrentFrame
        
    def isEnded(self):
        return self.mEnded
    
    def frameHasChanged(self):
        return self.mFrameHasChanged