-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathsimple_transition_pausing_from_Satheesh.lua
More file actions
188 lines (153 loc) · 5.38 KB
/
simple_transition_pausing_from_Satheesh.lua
File metadata and controls
188 lines (153 loc) · 5.38 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
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
-- A very Simple Pausable Transition
-- Author: Satheesh
-- Release date: 2011-11-27
-- Version: 1.0
-- License: MIT
-- Web: http:www.timeplusq.com
--
-- USAGE:
-- Import the module :
-- require "simple_transition_pausing_from_Satheesh"
--
-- Create transitions as usual
-- transition.to(object,params}
--
-- transition.pause(object) pauses all transitions of object
-- transition.resume(object) resumes all transitions of object
--
--
--
-- PROS
-- No extra code. Just use transitions as you used before
--
-- CONS
-- Delta transitions,easing not supported
-- (to be frank, i have no idea what they do :P)
-- May have minor bugs, since i haven't tested completely.
-- (works fine for my requirements though.. if you find any bug please commment)
--The transition.to and transiion.cancel functions are duplicated
local transitionToCopy = transition.to
local transitionCancelCopy = transition.cancel
--I override transition.to function with my function myTransitionFunction
--the duplicate i create is used to call the transition
local myTransitionFunction = function(object,params)
if not object.destination then
object.destination = {}
end
if not object.startTime then
object.startTime = {}
end
if not object.transition then
object.transition = {}
end
--object.destination - table storing transition parameters of each transition of the object
local transitionNo = #object.destination+1
object.destination [transitionNo] = {}
local destination = object.destination[transitionNo]
destination.x = params.x
destination.y = params.y
destination.xScale = params.xScale
destination.yScale = params.yScale
destination.time = params.time
destination.delay = params.delay
destination.onComplete = params.onComplete
destination.onStart = params.onStart
destination.alpha = params.alpha
destination.width = params.width
destination.height = params.height
destination.rotation = params.rotation
destination.xOrigin = params.xOrigin
destination.yOrigin = params.yOrigin
destination.maskX = params.maskX
destination.maskY = params.maskY
destination.maskScaleX = params.maskScaleX
destination.maskScaleY = params.maskScaleY
destination.maskRotation = params.maskRotation
destination.xReference = params.xReference
destination.yReference = params.yReference
if destination.delay== nil then
destination.delay=0
end
--on transition complete, deletes the corresponding table values for that particular transition
--and calls the onComplete function which was specified by the user
local onComplete = params.onComplete
params.onComplete = function(obj)
local localDestination = object.destination
for i =1,#localDestination do
if localDestination[i]==destination then
table.remove(object.destination,i)
table.remove(object.startTime,i)
table.remove(object.transition,i)
break
end
end
if onComplete then
onComplete(obj)
end
end
--object.startTime - table storing starting times of each transition of the object
--object.transition - table storing transition handles of each transition of the object
object.transition[transitionNo] = transitionToCopy(object,params)
object.transition[transitionNo].object = object
object.startTime[transitionNo] = system.getTimer()
return object.transition[transitionNo]
end
--Function that pauses all transitions of an object
local pause = function(object)
--object.pausedDestination - table storing transition parameters of each transition with time and delay adjusted after pause
object.pauedDestination = {}
--for each transition
for i =1,#object.startTime do
local object = object
local destination = object.destination[i]
local objTransition = object.transition[i]
local startTime = object.startTime[i]
object.pauedDestination[i] = destination
local pauedDestination = object.pauedDestination[i]
local currentTime = system.getTimer()
local delay = destination.delay
--time and delay adjustment
if (startTime+delay) > currentTime then
pauedDestination.delay = (startTime+delay)-currentTime
else
local timeRemaining = (startTime+delay+destination.time) - currentTime
pauedDestination.delay = nil
pauedDestination.time = timeRemaining
end
--cancel transition
transitionCancelCopy(objTransition)
end
--remove all transition properties of the object from the respective tables
object.destination = nil
object.objTransition = nil
object.startTime = nil
end
--resumes all paused transitions of the object
local resume = function(object)
--pausedDestination holds all transition parameters with adjustments for time and delay
local pauedDestination = object.pauedDestination
for i =1,#pauedDestination do
myTransitionFunction(object,pauedDestination[i])
end
end
--I override transition.cancel function with my function cancel
--the duplicate i created is used to cencel the transition
local cancel = function(transition)
local object = transition.object
local localTransition= object.transition
for i =1,#localTransition do
if localTransition[i]==transition then
table.remove(object.destination,i)
table.remove(object.startTime,i)
table.remove(object.transition,i)
break
end
end
transitionCancelCopy(transition)
end
--overriding transition.to and transition.cancel
--assigning transition.pause and transition.resume
transition.to=myTransitionFunction
transition.pause = pause
transition.resume = resume
transition.cancel = cancel