如何将等级框更改为在高分为0或之前未玩时不可用

我有3个等级框,每个框内包含等级数和高分,我想问如何更改等级2和3,在通过第一级之前不能点击。 --等级数 = 3

local i
for i = 1,等级数 do
    if i <= #levelScores then
        --首先是方块
        local sqaure = display.newImageRect(screenGroup,"images/block_green_brick.png"5050)
        sqaure.x = xStart +(rowControl * xOffset)
        sqaure.y = yStart +(yControl * yOffset); sqaure.id = i
        sqaure:addEventListener("tap",levelTouched)

        --然后是数字/分数文本
        local number = display.newText(screenGroup,i,00,native.sytemFontBold,18)
        number.x = sqaure.x; number.y = sqaure.y-10
        local score = display.newText(screenGroup,levelScores [i],00,native.sytemFontBold,17)
        score.x = sqaure.x; score.y = number.y + 24
    else --尝试更改为 elseif #levelScores == 0,但不起作用
        local sqaure = display.newImageRect(screenGroup,"images/block_green_question.png"5050)
        sqaure.x = xStart +(rowControl * xOffset)
        sqaure.y = yStart +(yControl * yOffset)
    end

    --控制变量
    rowControl = rowControl + 1
    if rowControl == amountPerRow then
        yControl = yControl + 1
        rowControl = 0
    end
end
点赞
用户5351988
用户5351988

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

以下是你所请求的确切代码:

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
2016-10-24 05:03:29