Helper method to reverse transitions.

Hi all,

I am wondering if it is possible to get the name of params passed to a function,  I am trying to write a helper module that I can use with transitions.  

Hopefully it will store the original values of an object before it is transitioned and then when a second function is called it will transition back to the original location.   I have it working for normal transitions, but I have just realized that for transition involving effects that the list of potential attributes is quite large.  Is there a way of converting the names of the params passed over so that I only store the ones that are changes and can just use these?  Any other ideas?

Cheers,

Here is my code.

[lua]

local transitionHelper = {}

local listOfObjects = {}

function transitionHelper:newObject( object, params )

if not listOfObjects[object] then

listOfObjects[object] = {}

listOfObjects[object].object = object 

print(“this is a new item”)

end

for k,v in pairs( params ) do

listOfObjects[object][k] = v

end

listOfObjects[object].xOld = object.x

listOfObjects[object].yOld = object.y

listOfObjects[object].rotationOld = object.rotation

listOfObjects[object].alphaOld = object.alpha

listOfObjects[object].xScaleOld = object.xScale

listOfObjects[object].yScaleOld = object.yScale

listOfObjects[object].widthOld = object.width

listOfObjects[object].heightOld = object.height

transition.to(object,{time = listOfObjects[object].time or 500, delay = listOfObjects[object].delay or 0,

delta = listOfObjects[object].delta, iterations = listOfObjects[object].iterations or 1,

tag = listOfObjects[object].tag, transition = listOfObjects[object].transition ,

x = listOfObjects[object].x, y = listOfObjects[object].y, rotation = listOfObjects[object].rotation,

alpha = listOfObjects[object].alpha, xScale = listOfObjects[object].xScale,

yScale = listOfObjects[object].yScale, width = listOfObjects[object].width,

height = listOfObjects[object].height, onComplete = listOfObjects[object].onComplete

})

end

function transitionHelper:returnObject( object, params )

transition.to(object,{time = params.time or listOfObjects[object].time or 500, 

delay = params.delay or listOfObjects[object].delay or 0,

delta = params.delta or listOfObjects[object].delta, 

iterations = params.iterations or listOfObjects[object].iterations or 1,

tag = params.tag or listOfObjects[object].tag, 

transition = params.transition or listOfObjects[object].transition ,

x = listOfObjects[object].xOld, y = listOfObjects[object].yOld, rotation = listOfObjects[object].rotationOld,

alpha = listOfObjects[object].alphaOld, xScale = listOfObjects[object].xScaleOld,

yScale = listOfObjects[object].yScaleOld, width = listOfObjects[object].widthOld,

height = listOfObjects[object].heightOld, onComplete = listOfObjects[object].onComplete

})

end

return transitionHelper

[/lua]

Thanks,

Craig

Hi Craig,

I don’t know if this helps or not, but you could use the “introspection” property to (potentially) get all of the object’s properties before the transition begins, and store that as a table of data to use when the transition reverses itself:

https://docs.coronalabs.com/api/type/DisplayObject/properties.html

Take care,

Brent

Thanks Brent,

Seems to work with the object itself, but this doesn’t list ‘effect’ properties, returns an error if I try it on .fill.effect, but worth a try.

[lua]

print("object._properties: " … json.prettify( redHelpButton._properties ) ) – works

print("pbject._properties: " … json.prettify( redHelpButton.fill.effect._properties ) ) – doesnt work

[/lua]

Craig

Hi Craig,

I don’t know if this helps or not, but you could use the “introspection” property to (potentially) get all of the object’s properties before the transition begins, and store that as a table of data to use when the transition reverses itself:

https://docs.coronalabs.com/api/type/DisplayObject/properties.html

Take care,

Brent

Thanks Brent,

Seems to work with the object itself, but this doesn’t list ‘effect’ properties, returns an error if I try it on .fill.effect, but worth a try.

[lua]

print("object._properties: " … json.prettify( redHelpButton._properties ) ) – works

print("pbject._properties: " … json.prettify( redHelpButton.fill.effect._properties ) ) – doesnt work

[/lua]

Craig