0

当我点击一个对象时,我想调用 removeBody 函数。一旦我单击对象,必须在对象上调用 removeBody 函数,并且在我释放鼠标后,它必须再次表现得像物理对象一样。这些是我正在尝试的代码。请给任何建议

local function removephysics(objId)
   physics.removeBody(objId)
end

local Bodyobject={density=3.0, friction=0.2, bounce=0.3, radius=20}

object1=display.newImage("img1.png")
object1.x=325
object1.y=200
object1.id="obj"
physics.addBody(object1,Bodyobject)
object1.addEventListener("touch",removephysics)
4

1 回答 1

0

您可以使用event.phase获取触摸侦听器的状态查看此代码

physics = require("physics")
physics.start()

local Bodyobject={density=3.0, friction=0.2, bounce=0.3, radius=20}
function removephysics(event)
   if event.phase == "began" then
      physics.removeBody(object1)
   elseif event.phase == "ended" then
      physics.addBody(object1,Bodyobject)
   end
end


object1=display.newImage("img1.png")
object1.x=325
object1.y=200
object1.id="obj"
physics.addBody(object1,Bodyobject)
object1:addEventListener("touch",removephysics)
于 2013-08-04T02:19:52.867 回答