i have a problem with transitioning! For example: i have an object and a button. I want this object to fade out when i press the button, and then when i press the button again i want my object to fade in. But i can't fade in my object, feels like it's just gone! For transition i use transition.to, for ex:
object = transition.to( object, {time=500, alpha=0})
but when i perform another function in this exact scene to fade in, it just don't wanna work at all(button is pressing, but nothing is happening, even errors).
Help me out please!
Your code:
object = transition.to( object, {time=500, alpha=0})
You are saving the transition handler to the object. Try this:
trans = transition.to( object, {time=500, alpha=0})
Then if you want to cancel the transition you can do this
transition.cancel(trans)
you can check the the usage of transition.to here http://developer.coronalabs.com/node/2407
Cheers!
Try this code i don't know correctly but it's works well:
local myRectangle = display.newRect(100, 100, 150, 50)
myRectangle.strokeWidth = 3
myRectangle:setFillColor(140, 140, 140)
myRectangle:setStrokeColor(180, 180, 180)
local button = display.newRect(100, 200, 50, 50)
button.strokeWidth = 3
button:setFillColor(140, 140, 140)
button:setStrokeColor(180, 180, 180)
local buttonfun=function(event)
if event.phase=="ended" then
print("fade")
if myRectangle.alpha ==1.0 then
transition.to( myRectangle, { delay=1, time=1000, alpha=1.0, alpha=0.0} )
myRectangle.alpha=0.0
print("alpha"..myRectangle.alpha)
else
transition.to( myRectangle, { delay=1, time=1000, alpha=0.0, alpha=1.0} )
myRectangle.alpha=1.0
print(myRectangle.alpha)
end
end
return true
end
button:addEventListener("touch", buttonfun)
After you write this trans = transition.to( object, {time=500, alpha=0})
in button pressed first time so you must chick make boolen variable to make this action twice. and second time which fade it in again you must make alpha=1
For example:
local trans
function Listner (event)
transition.cancel(trans)
trans = nil
end
function onPress(event)
if(flage== true) then
flage = false
trans = transition.to( object, {time=500, alpha=0 , onComplete =Listner })
else
flage = true
trans = transition.to( object, {time=500, alpha=1 , onComplete =Listner })
end
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.