/ld27

To get this branch, use:
bzr branch http://9ix.org/bzr/ld27

« back to all changes in this revision

Viewing changes to zoetrope/sprites/animation.lua

  • Committer: Josh C
  • Date: 2013-08-25 00:16:36 UTC
  • Revision ID: josh@9ix.org-20130825001636-xoivc9byo1mdx0fu
1 goal in each maze

Show diffs side-by-side

added added

removed removed

Lines of Context:
7
7
-- Event: onEndSequence
8
8
-- Called whenever an animation sequence ends. It is passed the name
9
9
-- of the sequence that just ended.
10
 
--
 
10
-- 
11
11
-- Extends:
12
12
--              <Sprite>
13
13
 
14
 
Animation = Sprite:extend
15
 
{
 
14
Animation = Sprite:extend{
16
15
        -- Property: paused
17
16
        -- Set this to true to freeze the animation on the current frame.
18
17
        paused = false,
63
62
                return obj
64
63
        end,
65
64
 
66
 
        -- Method: play
 
65
        -- Method: play 
67
66
        -- Begins playing an animation in the sprite's library.
68
67
        -- If the animation is already playing, this has no effect.
69
68
        --
77
76
                if self.currentName == name and not self.paused then
78
77
                        return
79
78
                end
80
 
 
 
79
                
81
80
                assert(self.sequences[name], 'no animation sequence named "' .. name .. '"')
82
 
 
 
81
                
83
82
                self.currentName = name
84
83
                self.currentSequence = self.sequences[name]
85
84
                self.frameIndex = 0
102
101
                if self.currentSequence then
103
102
                        index = index or self.currentSequence[self.frameIndex]
104
103
                end
105
 
 
 
104
                
106
105
                index = index or self.currentFrame or 1
107
106
 
108
107
                if self._set.image ~= self.image then
125
124
        --              nothing
126
125
 
127
126
        updateQuad = function (self)
128
 
                if self.image then
 
127
                if self.image then 
129
128
                        self._imageObj = Cached:image(self.image)
130
129
                        if not self.width then self.width = self._imageObj:getHeight() end
131
130
                        if not self.height then self.height = self.width end
166
165
 
167
166
                if self.currentSequence and not self.paused then
168
167
                        self.frameTimer = self.frameTimer - elapsed
169
 
 
 
168
                        
170
169
                        if self.frameTimer <= 0 then
171
170
                                self.frameIndex = self.frameIndex + 1
172
171
 
202
201
                end
203
202
 
204
203
                if not self.visible or not self.image or self.alpha <= 0 then return end
205
 
 
 
204
                
206
205
                -- if our image changed, update the quad
207
 
 
 
206
                
208
207
                if self._set.image ~= self.image then
209
208
                        self:updateQuad()
210
209
                end
211
 
 
 
210
                
212
211
                -- set color if needed
213
212
 
214
213
                local colored = self.alpha ~= 1 or self.tint[1] ~= 1 or self.tint[2] ~= 1 or self.tint[3] ~= 1
224
223
 
225
224
                if self.flipX then scaleX = scaleX * -1 end
226
225
                if self.flipY then scaleY = scaleY * -1 end
227
 
 
228
 
                local origX = self.origin.x or (self.width / 2)
229
 
                local origY = self.origin.y or (self.height / 2)
230
 
 
231
 
                love.graphics.draw(self._imageObj, self._quad, x + origX, y + origY, self.rotation,
232
 
                                                        scaleX, scaleY, origX, origY)
233
 
 
 
226
                        
 
227
                love.graphics.drawq(self._imageObj, self._quad, x + self.width / 2, y + self.height / 2, self.rotation,
 
228
                                                        scaleX, scaleY, self.width / 2, self.height / 2)
 
229
                
234
230
                -- reset color
235
 
 
 
231
                
236
232
                if colored then
237
233
                        love.graphics.setColor(255, 255, 255, 255)
238
234
                end
239
235
        end,
240
236
 
241
237
        __tostring = function (self)
242
 
                local result = 'Animation (x: ' .. tostring(self.x) .. ', y: ' .. tostring(self.y) ..
243
 
                                           ', w: ' .. tostring(self.width) .. ', h: ' .. tostring(self.height) .. ', '
 
238
                local result = 'Animation (x: ' .. self.x .. ', y: ' .. self.y ..
 
239
                                           ', w: ' .. self.width .. ', h: ' .. self.height .. ', '
244
240
 
245
241
                if self.currentName then
246
242
                        result = result .. 'playing ' .. self.currentName .. ', '
247
243
                end
248
244
 
249
 
                result = result .. ' frame ' .. tostring(self.currentFrame) .. ', '
 
245
                result = result .. ' frame ' .. self.currentFrame .. ', '
250
246
 
251
247
                if self.active then
252
248
                        result = result .. 'active, '