Corona SDK中的PurgeScene销毁了物理引擎。

我已经创建了一个简单的滚动游戏,紧随Mark Farkland的游戏教程。我清楚地遵循了他的编码模式,但到了我迷失方向并且不知道为什么我的游戏行为与他的例子不同的地步。直到一个场景被清除之后,一切都运行良好。

我有两个Lua文件:游戏.lua和gameover.lua。请注意:在Game.lua的exitScene中,我已经删除了所有的事件监听器。在gameover.lua的enterScene中,我清除了game.lua场景。当用户触摸屏幕时,它会加载game.lua文件。每个对象都会像新的一样加载和刷新,除了主要对象,它只是向上射击。

游戏.lua

     local storyboard = require("storyboard")
     local scene = storyboard.newScene()
     local physics = require("physics")

     function scene:createScene(event)
         物理开始()
         ....
         local jet = 显示.newImage("images/jet_normal.png")
         物理.addBody(jet,"dynamic",{density=.07,bounce=0.1,friction=.2,radius=12)

         本机激活=函数(self,事件)
             自我applyForce(0-1.5,自我X,自我Y)
         结束

         函数touchScreen(事件)
             本地阶段=事件阶段
             如果阶段== "开始"那么
                 jet.enterFrame = activateJets
                 Runtime:addEventListener("enterFrame",jet)
             结束
             如果阶段== "ended"那么
                 Runtime:removeEventListener("enterFrame",jet)
             结束
         结束

         Runtime:addEventListener("touch",touchScreen)
 end

 函数场景:exitScene(事件)
     Runtime:removeEventListener("touch",touchScreen)
     Runtime:removeEventListener("enterFrame",enemy1)
     Runtime:removeEventListener("collision",onColission)
 结束

GameOver.lua

函数开始(事件)
     如果阶段== "开始"那么
         storyboard.gotoScene("game""fade"100)
     结束
 结束

 函数场景:enterScene(事件)
     storyboard.purgeAll("game")
     背景:addEventListener("touch",start)
 结束

 函数场景:exitScene(事件)
     背景:removeEventListener("touch",start)
 结束
点赞
用户822240
用户822240

你需要将 jet 添加到当前的组中。

function scene:createScene(event)
   local group = self.view
   --...
   local jet = display.newImage("images/jet_normal.png")
   --...
   group:insert(jet)
   Runtime:addEventListener("touch", touchScreen)
end

当触发 exitScene 时,该组会进行适当的清理。

更多信息/不同的实现方法:

http://docs.coronalabs.com/guide/graphics/group.html

2014-02-26 00:11:39