/ld27

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

« back to all changes in this revision

Viewing changes to zoetrope/core/tween.lua

  • Committer: Josh C
  • Date: 2013-08-25 00:32:21 UTC
  • Revision ID: josh@9ix.org-20130825003221-632jbug07yhqabuo
pickĀ upĀ goals

Show diffs side-by-side

added added

removed removed

Lines of Context:
102
102
                        assert(self.easers[ease], 'easer ' .. ease .. ' is not defined')
103
103
                end
104
104
 
105
 
                local tween = { target = target, property = property, propType = propType, to = to, duration = duration, ease = ease }
 
105
                -- check for an existing tween for this target and property
 
106
                
 
107
                for i, existing in ipairs(self.tweens) do
 
108
                        if target == existing.target and property == existing.property then
 
109
                                if to == existing.to then
 
110
                                        return existing.promise
 
111
                                else
 
112
                                        table.remove(self.tweens, i)
 
113
                                end
 
114
                        end
 
115
                end
 
116
                
 
117
                -- add it
 
118
 
 
119
                tween = { target = target, property = property, propType = propType, to = to, duration = duration, ease = ease }
106
120
                tween.from = self:getTweenValue(tween)
107
121
                tween.type = type(tween.from)
108
122
                
132
146
                else
133
147
                        error('tweened property must either be a number or a table of numbers, is ' .. tween.type)
134
148
                end
135
 
 
136
 
                -- check for an existing tween for this target and property
137
 
                
138
 
                for i, existing in ipairs(self.tweens) do
139
 
                        if target == existing.target and property == existing.property then
140
 
                                if to == existing.to then
141
 
                                        return existing.promise
142
 
                                else
143
 
                                        existing.promise:fail('Overridden by a later tween')
144
 
                                        table.remove(self.tweens, i)
145
 
                                end
146
 
                        end
147
 
                end
148
 
                
 
149
                        
149
150
                tween.elapsed = 0
150
151
                tween.promise = Promise:new()
151
152
                table.insert(self.tweens, tween)
196
197
                           (type(tween.property) == 'table' and tween.property[1] == property) or
197
198
                           not property) then
198
199
                                found = true
199
 
                                tween.promise:fail('Stopped')
 
200
                                tween.promise:fail('Tween stopped')
200
201
                                table.remove(self.tweens, i)
201
202
                        end
202
203
                end