2013-10-24 26 views
1

對於我的代碼(corona SDK),我有一個任意顯示對象「激光」在我觸摸時淡出,並在我放開時重新顯示。然而;在onTouch函數中,如果我將「開始」轉換alpha設置爲0而不是大於0的任何值,那麼我的顯示對象將永久保持隱藏在0 alpha處。是什麼賦予了?下面的代碼(現在,我使用的α= 0.01,因爲它是非常接近):Corona SDK:如何在轉換完成後重新創建對象?

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 

回答

0

如果你想阻止一個過渡,使用此:

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 
0

過渡。在選項中支持和onComplete參數,這樣當轉換完成時,可以調用一個函數,並且在該函數中,可以重新設置任何需要的值。

相關問題