Yeah I know there are a lot of transition managers.. Still never hurts to share code.. So here goes.
USAGE :
1 2 3 | transition.to(object,params} transition.pause(object) transition.resume(object) |
I am not sure about the efficiency of this module. So if anyone has any modifications or if anyone finds any bug, please comment below.
And I haven't tested this completely, but till now, it has worked fine for me :)
https://github.com/SatheeshJM/simple_transition_pausing_from_Satheesh
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 let me know) --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 |
I haven't included pausing of transition.dissolve in the module.. will try to include that too!
That and pause-resuming of individual transitions coming up!
ok..Looking forward to it...:)
I am moving a display group
1 2 3 4 5 6 7 8 | function moveGroup(params) moveOrderTime = params.time moveOrderX = params.x moveOrderY = params.y output = transition.to(displayGroup,{time = moveOrderTime, x = moveOrderX, y = moveOrderY, onComplete = resetGroup}) return output end |
then trying to pause it when it collides with something, and resume when the collision has ended
1 2 3 4 5 6 7 8 | function onLocalCollision(event) if (event.phase=="began") then transition.pause(displayGroup) end if (event.phase=="ended") then transition.resume(displayGroup) end end |
but it complains that pause is a nil value.
EDIT: solved it, the module hadn't saved -_-
is there a way to pause and resume a table of elements using this ?eg.
1 | transition.to(blackText[i],{delay=delay1,time=trans1,alpha=0}) |
and then you can pause and resume this using
transition.pause(blackText[i]) and transition.resume(blackText[i])
Is this possible?
can I pause transition.dissolve using the above method.If so ,how can I do it.I have two transition.dissolve
al=transition.dissolve(blackText[i],redText[i],trans1,delay1)
bl=transition.dissolve(redText[i],blackText[i],trans2,delay2)
Now I need to pause and resume the above transitions.How can i do it?
Coz when I did what u have said in the following method I am getting an error
Copyright (C) 2009-2011 A n s c a , I n c .
Version: 2.0.0
Build: 2011.591
--------------------------------------------------------------------
Runtime error
...\simple_transition_pausing_from_Satheesh.lua:122: attempt to
index local 'object' (a nil value)
stack traceback:
[C]: ?
...\simple_transition_pausing_from_Satheesh.lua:122: in function
'pause'
...sers\Rahul Singh\Deskt
Please take me out of this problem