2014-09-13 90 views
0

我試圖在我的函數中停止3個動畫,當它達到某個點時,然後顯示消息「動畫已停止」。需要幫助停止corona的功能

我該怎麼做?我知道display.NewText(),但我會如何去停止動畫並讓消息同時彈出?

這是我試圖阻止的功能。

WIDTH = display.contentWidth 
HEIGHT = display.contentHeight 
--displays background 
local s = display.newImageRect("space.png" ,1136, 640) 
s.x = 900/2 
s.y = 500/2 

--display main ship 
local r = display.newImageRect("ship.png", 70, 70) 
r.x = 20 
r.y = 450 

local minions = {} 

function createMinions() 
    local x = 40 
local y = 120 
for n = 1, 20 do -- displays 20 minions 
    local minion = display.newImageRect("minion.png", 50, 50) 
    minion.x = x 
    minion.y = y 

    minions[n] = minion 
    x = x + 60 -- next enemy will be to the right 
    if x >= WIDTH then -- start a new row if necessary 
     y = y + 60 -- seperation between minions 
     x = 40 
     end 
    end 
end 

--display mothership 
m = display.newImageRect("mothership.png", 150, 150) 
m.x = 160 
m.y = 10 

function nextFrame() 
-- begins movements of main ship to right 
r.x = r.x + 5 
if r.x > 350 then 
    r.x = -100 
end 
-- begins movement of minions to the left 
    for i = 1, 20 do 
     local minion = minions[i] 
     minion.x = minion.x - 8 
     if minion.x < -100 then 
      minion.x = 400 
     end 
    end 
--begins movement of mothership towards small ship 
    m.y = m.y + 10 
    if m.y > 460 then 
     m.y = -100 
    end 
    --stops all animations 
    if m.y > 450 then 
     --r.x = r.x + 0 
     --m.y = m.y + 0 
     --minion.x = minion.x + 0 
     local s = true 
     --displays game over text 
     s = display.newText("Game Over", WIDTH/2, 400, native, 30) 

    end 

end 
createMinions() 

Runtime:addEventListener("enterFrame", nextFrame) 

--hides status bar 
display.setStatusBar(display.HiddenStatusBar) 
+0

你是什麼意思,你試圖「停止」它?只是停止調用它?你需要告訴我們你在哪裏打電話給我們,告訴你如何阻止它。 – 2014-09-13 10:46:27

+0

好吧剛從corona發佈了整個腳本。我只是想讓我的動畫中的所有對象在m.y> 450時立即停止,並將遊戲顯示爲符號 – Chris 2014-09-13 17:08:37

+0

只需在'if(m.y <450),然後YOURCODE結束' – 2014-09-13 18:20:15

回答