如何在进入日冕屏幕之前暂停物理对象?

时间:2017-02-14 16:44:41

标签: lua corona game-physics

我使用physics.pause()physics.start(),但是我的问题是一个函数在底部继续显示一个对象,当我恢复游戏时,这些对象被编译并且所有对象都进入屏幕立刻。我希望有人可以帮助我。

这是我的代码:

local isPaused = false

    function pausePhysics( event )
        if "began" == event.phase then
            if isPaused == false then
                physics.pause(lobo)
                isPaused = true
                    timer.pause(countDownTimer)

                    local decide = display.newImage("wood.png")
                        decide.x = display.contentWidth*0.5
                        decide.y = display.contentHeight*0.5
                    local yes
                    local no

                    local function oo()
                        if score == 0 then
                            onBackBtnRelease()
                        elseif score >0 and score <=10 then
                            GameOver1()
                        elseif score >10 and score <=20 then
                            GameOver2()
                        else
                            GameOver3()
                        end
                    end

                    yes = widget.newButton
                    {
                        defaultFile= "yes.png",
                        width=100, height=50,
                        onRelease = oo  
                    }
                    yes.x = display.contentWidth*0.3
                    yes.y = display.contentHeight - 200

                    local function hindi()
                        if isPaused == true then
                        physics.start()
                        isPaused = false
                            timer.resume(countDownTimer)

                            display.remove(decide)
                            decide = nil
                            display.remove(yes)
                            yes = nil
                            display.remove(no)
                            no = nil
                            end
                        return true
                    end

                    no = widget.newButton
                    {
                        defaultFile= "no.png",
                        width=100, height=50,
                        onRelease = hindi   
                    }
                    no.x = display.contentWidth*0.7
                    no.y = display.contentHeight - 200

                    sceneGroup:insert(decide)
                    sceneGroup:insert(yes)
                    sceneGroup:insert(no)
            return true
            end
        end
    end

local function tapos(event)
    if (event.phase == "began") then
        physics.addBody(backBtn, "static")

    end
end
Runtime:addEventListener("enterFrame", backBtn)
backBtn:addEventListener("touch", pausePhysics)

local function ulit()
    local mRandom = math.random
    local balloon = { ("blue.png"), ("green.png"), ("red.png"), ("orange.png"), ("pink.png"), ("violet.png"), ("yellow.png"), ("blue2.png"), ("green2.png"), ("red2.png"), ("orange2.png"), ("pink2.png"), ("violet2.png"), ("yellow2.png") }
    local lobo = display.newImage( balloon[mRandom(10)], mRandom(30,270), mRandom(550,650) )
    physics.addBody( lobo, { density=0.1, friction=2.0, bounce=0.0, velocity=-40, isSensor=true } );

end

timer.performWithDelay(300,ulit,0)

0 个答案:

没有答案
相关问题