简体   繁体   中英

Corona SDK: How to make an object transition back in after transition completion?

For my code (corona SDK), I'm having an arbitrary display object "laser" fade out when I touch it, and back in when I let go. However; in the onTouch function, if I set the "began" transition alpha to 0 instead of anything > 0, then my display object permanently stays hidden at 0 alpha. What gives? Here's the code (for now, I'm using alpha = 0.01, since it's pretty close):

local function fadeBack(var)
      transition.to(laser, {time = 700, alpha = 1.0});
end

local function onTouch(event)
    if(event.phase == "began")then
    tween = transition.to(laser, {time = 100, alpha = 0});
     elseif(event.phase == "ended") then
    fadeBack();
     end
end

If you're trying to stop a transition, use this:

local trans

local function fadeBack()
    transition.cancel(trans)
end

local function onTouch(event)
    if event.phase == "began" then
        trans = transition.to(laser, {time = 100, alpha = 0})
    elseif event.phase == "ended" then
        fadeBack()
    end
end

选项中的transition.to支持和onComplete参数,以便在完成转换后可以调用一个函数,并且可以在该函数中重置所需的内容。

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.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM