Function 需要帮助停止corona中的功能吗
我试图在我的函数中停止3个动画,当它达到某一点时,会显示一条消息“animations Stopped”(动画停止) 我该怎么做?我知道display.NewText(),但是如何停止动画并同时弹出消息呢 这是我试图停止的函数Function 需要帮助停止corona中的功能吗,function,lua,coronasdk,Function,Lua,Coronasdk,我试图在我的函数中停止3个动画,当它达到某一点时,会显示一条消息“animations Stopped”(动画停止) 我该怎么做?我知道display.NewText(),但是如何停止动画并同时弹出消息呢 这是我试图停止的函数 WIDTH = display.contentWidth HEIGHT = display.contentHeight --displays background local s = display.newImageRect("space.png" ,1136, 640)
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 )
WIDTH=display.contentWidth
高度=display.contentHeight
--显示背景
本地s=display.newImageRect(“space.png”,1136640)
s、 x=900/2
s、 y=500/2
--显示主船
本地r=display.newImageRect(“ship.png”,70,70)
r、 x=20
r、 y=450
本地仆从={}
函数createMinions()
局部x=40
局部y=120
对于n=1,20 do——显示20个仆从
本地minion=display.newImageRect(“minion.png”,50,50)
仆从.x=x
仆从y=y
仆从
x=x+60——下一个敌人将在右边
如果x>=WIDTH,则--如有必要,启动新行
y=y+60——仆从之间的间隔
x=40
结束
结束
结束
--显示母舰
m=display.newImageRect(“mothership.png”,150150)
m、 x=160
m、 y=10
函数nextFrame()
--主船开始向右移动
r、 x=r.x+5
如果r.x>350,则
r、 x=-100
结束
--开始爪牙向左移动
对于i=1,20 do
本地仆从=仆从[i]
minion.x=minion.x-8
如果minion.x<-100,则
仆从x=400
结束
结束
--开始母船向小船移动
m、 y=m.y+10
如果m.y>460,则
m、 y=-100
结束
--停止所有动画
如果m.y>450,则
--r、 x=r.x+0
--m、 y=m.y+0
--仆从.x=仆从.x+0
局部s=真
--在文本上显示游戏
s=display.newText(“游戏结束”,宽度/2400,本机,30)
结束
结束
createMinions()
运行时:addEventListener(“enterFrame”,nextFrame)
--隐藏状态栏
display.setStatusBar(display.HiddenStatusBar)
只是让它非常简短-
这是特定于您的问题的代码
if(m.y < 450) then YOURCODE else DISPLAYTEXTCODE end
如果(m.y<450),则代码else显示TEXTCODE end
对于未来,我建议人们关注:
-移动显示对象
及
-根据事件触发代码。您试图“停止”代码是什么意思?别再叫了?你需要告诉我们你在哪里呼叫它,让我们告诉你如何阻止它。好的,刚刚发布了科罗纳的整个脚本。我只想让我的动画中的所有对象在m.y>450时立即停止,并在标志牌上显示游戏。只需将其全部包装在“如果(m.y<450),则代码结束”中即可。但是,如何使文本仅在所有对象停止时才显示?因为现在它从动画开始就在那里。
if(m.y<450)那么你的代码else显示textcode end
-但是听起来你设计的好像是错误的。您应该研究侦听器和转换。