這是更好地創建這兩個圖像進行匹配自己的立場:
local lana = display.newImageRect("images/lana_zero.png", 70, 100)
lana.anchorX = 0
lana.anchorY = 1
lana.x, lana.y = 0, 100
local lana1 = display.newImageRect("images/lana_one.png", 70, 100)
lana1.anchorX = 0
lana1.anchorY = 1
lana1.x, lana1.y = 0, 100
lana1.alpha = 0
,然後在點擊阿爾法切換到1
local touchHandler = function(event)
if event.phase == "ended" then
if whichLanaIsVisible == 0 then
lana.alpha = 0
lana1.alpha = 1
whichLanaIsVisible = 1
else
lana.alpha = 1
lana1.alpha = 0
whichLanaIsVisible = 0
end
end
end
button:addEventListener("touch", touchHandler)
警告! 你不能這樣做if lana.alpha == 0
,因爲alpha,即使設置爲0也不一定總是等於0.那麼它幾乎爲0。它可能是0.00002501,例如它不等於0.
您應該使用'isVisible'標誌,而不是將alpha更改爲0. –
這是真的,但您可以執行transition.to並執行fadeout,如果您使用alpha而不是isVisible – Lukis
,那麼您可以使用'transition.dissolve()'http://docs.coronalabs.com/api/library/transition/dissolve.html –