How to use a variable as a property in transition

Hi, is there any way to pass a variable for the property to be transitioned?

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
local myRectangle = display.newRect(0, 0, 150, 50)
myRectangle.strokeWidth = 3
myRectangle:setFillColor(140, 140, 140)
myRectangle:setStrokeColor(180, 180, 180)
 
--does not work
--[[
local transitionProperty = alpha
 
transition.to( myRectangle , {time=400, transitionProperty =  0 , transition=easing.outExpo })  
--]]
 
--does not work
--[[
transitionProperty = "alpha"
 
transition.to( myRectangle , {time=400, transitionProperty =  0 , transition=easing.outExpo })  
--]]
 
--does work, obviously :)
transition.to( myRectangle , {time=400, alpha=  0 , transition=easing.outExpo })                

Yes, although I can't work out what you are doing exactly above.

As an example, if you had a variable for transTime = 1000 you could pass it by doing this;

transition.to(myRectangle{time = transTime, x = 100, y = 100})

Make sense?

Thanks for using Lua tags to post your code; when people don't it's a real pain ;)

Hi Peach, thanks for your reply, however I'm not trying to pass a value for a property

ie

1
2
3
local myval = 100
 
transition.to(myRectangle{time = 100, x= myval})

I figured it out!

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
local myRectangle = display.newRect(0, 0, 150, 50)
myRectangle.strokeWidth = 3
myRectangle:setFillColor(140, 140, 140)
myRectangle:setStrokeColor(180, 180, 180
 
local transData= {}
 
transData.time=400
transData.transition=easing.outExpo 
 
if(somecondition~=true) then
transData.x=0                                   
else
transData.y=0                                   
end
 
transition.to( myRectangle , transData)

D'oh! Sorry, I completely misunderstood.

.... I really should stop forum lurking when I'm not all caffeinated ;)

views:1397 update:2011/9/28 21:38:26
corona forums © 2003-2011