检查图像是否可见(CoronaSDK)

时间:2014-03-02 03:26:03

标签: android image lua corona

我是coronaSDK的新手,我现在面临一个问题。我只是想知道如何检查图像是否可见。

local function buttonListener1( event )
    local lockedImage = display.newImage("locked.png")
    lockedImage.x = 240
    lockedImage.y = 170
    lockedImage.isVisible = true
    local myClosure = function() lockedImage.isVisible = false end
    timer.performWithDelay(1000,myClosure)
end

我想要做的是首先检查lockedImage是否可见。如果true,那么lockedImage一旦触发就不会再出现。否则,它将出现并执行timer.performWithDelay(1000,myClosure)。任何帮助都是真诚的感谢。对不起我的英语不好。提前谢谢!

1 个答案:

答案 0 :(得分:1)

怎么样:

if myImage.isVisible then 
     ... do something ...
end

但要执行您所描述的内容,必须在buttonListener1之外创建lockedImage,因此上述技术意味着:

local lockedImage = display.newImage("locked.png")
lockedImage.x = 240
lockedImage.y = 170
lockedImage.isVisible = false
lockedImage:addEventListener...

... presumably some listener might toggle lockedImage.isVisible 
    to true at some point ...

-- some button listener: 
local function buttonListener1( event )
    if lockedImage.isVisible == false then
        -- show for one second
        lockedImage.isVisible = true 
        local myClosure = function() lockedImage.isVisible = false end
        timer.performWithDelay(1000, myClosure)
    end
end