2014-06-08 31 views
0

我正在使用Corona SDK,目前我有这个。当你点击图片时,数字会增加。我很奇怪,一旦达到一定的点击次数,我将如何改变图像?如何根据Corona中的水龙头数量更改图像?

display.setStatusBar(display.HiddenStatusBar) 

    local newButton = display.newImage ("button.png",0,0) 
    newButton.x = display.contentWidth - 60 
    newButton.y = display.contentHeight - 62.5 

    local number = 0 
    local textField = display.newText(number, 30, 30, native.systemFont, 25) 

    local function moveButtonRandom(event) 
     number = number + 1 
     textField:removeSelf() 
     textField = display.newText(number, 30, 30, native.systemFont, 25) 
    end 


    newButton:addEventListener("tap", moveButtonRandom) 

回答

0

您可以使如果再决策声明中的功能和使用数字作为论据。当声明真正切换图片。

示例:如果数> = 3然后 - [[3次后点击删除现有的图片,并添加新的图象代码执行这里 - ]] 结束

好运

0

例如,如果你要的图像显示出来,当你到了15次点击,你可以修改你轻点功能,看起来像这样,让数字变由图像代替:

local function moveButtonRandom(event) 
    number = number + 1 

    -- Here goes our if check 

    if number >= 15 then 
     -- The number of clicks is 15 or more, replace the numbers with an image 
     textField:removeSelf() 
     textField = display.newImage("yourImage.png") 
    else 
     -- Do things the 'normal' way 
     textField:removeSelf() 
     textField = display.newText(number, 30, 30, native.systemFont, 25) 
    end 
end 

如果你不想要的图片取代文字,然后创建一个新的局部变量位于文件顶部,并将其分配给if检查

相关问题