0

コロナSDKを使ってアプリを作っています。ゲームでは、時間内にすべての球に触れる必要があり、勝つと勝利の画像が表示されます。「あなたが勝つ」メッセージの下にリプレイ ボタンを作成しましたが、ゲーム全体を再開するように彼に言うにはどうすればよいですか?

コードは次のとおりです (すべてではありません)。

function winLose(condition)
if condition == "Win" then
    print ("Winner")
    winMSG = display.newImage("media/win.png")


    -- Replay button

    local btnReplay = ui.newButton{
    default = "media/buttonWhite.png",
    over = "media/buttonWhiteOver.png",
    onPress = btnReplayPress,
    onRelease = btnReplayRelease,
    text = "Replay",
    textColor = { 0, 0, 0, 255 },
    size = 26,
    id = "replay",
    emboss = true
    }

    btnReplay.x = _W/2; 
    btnReplay.y = _H/2 + 50;

elseif condition == "Fail" then

    print ("Loser")
    loseMSG = display.newImage("media/lose.png")

    -- Replay Button

    btnReplay = ui.newButton{
    default = "media/buttonWhite.png",
    over = "media/buttonWhiteOver.png",
    onPress = btnReplayPress,
    onRelease = btnReplayRelease,
    textColor = { 0, 0, 0, 255 },
    size = 26,
    text = "Replay"
    id = "replay",
    emboss = true
    }


    -----

    function btnReplay:touch(e)
        if e.phase == "began" then
            --
        elseif e.phase == "moved" then
            --
        elseif e.phase == "ended" then
            -- Here I should say what it has to do to replay
        end
    end

    -----

    btnReplay:addEventListener( "touch", btnReplay);

    -----

    btnReplay.x = _W/2; 
    btnReplay.y = _H/2 + 50;
end
end

local function trackOrbs(obj)
obj:removeSelf()
o = o-1;

if time_up ~= true then
    if (o == 0) then
        timer.cancel(gametmr);
        winLose("Win");
    end
end
end 

local function countDown (e)
if (time_remain == total_secs) then
    ready = true
end
time_remain = time_remain - 1;
countdowntxt.text = time_remain;

if time_remain == 0 then
    time_up = true

    if o ~= 0 then
        winLose("Fail");
        ready = false;
    end
end
end


local function spawnOrb()

local orb = display.newImageRect("media/orb.png", 60, 60);
orb:setReferencePoint(display.CenterReferencePoint);
orb.x = mRand(50, _W-50); orb.y = mRand (50, _H-50);

function orb:touch(e)
    if time_up ~= true then
        if (ready == true) then
            if (e.phase == "ended") then
                trackOrbs(self);
            end 
        end 
    end

    return true
end

o = o + 1;

orb:addEventListener("touch", orb);

if (o == total_orbs) then
    gametmr =   timer.performWithDelay(1000, countDown, total_secs) ;
else
    ready = false
end
 end

 tmr = timer.performWithDelay (20, spawnOrb, total_orbs);
4

1 に答える 1

0

このようなwhileループを持つことができます

while true do 
    if mainGame then
        --game code
    elseif done then
        --buttons
        if button.restart then
            mainGame = true
        end
    end
 end
于 2013-02-27T05:32:35.377 に答える