我想在点击一个对象时调用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)
答案 0 :(得分: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)