如果高分为0或之前未播放,如何更改级别框以使其不可用

时间:2016-10-20 07:58:34

标签: lua

我有这3个盒子的等级,每个盒子包含等级数和高分,我想问一下如何更改等级2和3无法在清除第一等级之前点击。 --amountOfLevels = 3

local i
for i=1, amountOfLevels do
    if i <= #levelScores then
        --First the sqaure
        local sqaure = display.newImageRect(screenGroup, "images/block_green_brick.png", 50, 50)
        sqaure.x = xStart + (rowControl*xOffset)
        sqaure.y = yStart + (yControl*yOffset); sqaure.id = i
        sqaure:addEventListener("tap", levelTouched)

        --Then the number/score text.
        local number = display.newText(screenGroup, i, 0,0, native.sytemFontBold, 18)
        number.x = sqaure.x; number.y = sqaure.y-10
        local score = display.newText(screenGroup, levelScores[i], 0,0, native.sytemFontBold, 17)
        score.x = sqaure.x; score.y = number.y+24
    else --tried to change tobe elseif #levelScores == 0 but doesnt work
        local sqaure = display.newImageRect(screenGroup, "images/block_green_question.png", 50, 50)
        sqaure.x = xStart + (rowControl*xOffset)
        sqaure.y = yStart + (yControl*yOffset)
    end

    --Control variables.
    rowControl = rowControl + 1
    if rowControl == amountPerRow then
        yControl = yControl + 1
        rowControl = 0
    end
end

1 个答案:

答案 0 :(得分:0)

由于缺少代码,我在这里猜测我的代码正在做什么。

准确地告诉你你的问题:

local function levelTouched(event)
    local lv = event.target.id
    if lv==1 or tonumber(levelScores[1])>0 then
        currentLevel = lv
        storyboard.gotoScene( "game", "slideLeft", 400 )
    end
end

现在,如果您想要在前一个级别尚未清除的情况下使任何级别不可用:

local function levelTouched(event)
    local lv = event.target.id
    if lv==1 or tonumber(levelScores[lv-1])>0 then
        currentLevel = lv
        storyboard.gotoScene( "game", "slideLeft", 400 )
    end
end