在我的游戏中,我有左右侧按钮。如果人到达左侧按钮获得负值的重力。右侧加值。如何设置x和-x方向的碰撞检测。
local function onLocalPreCollision( self, event )
if (left.name == "left") then
physics.setGravity(-10,0)
end
if (right.name == "right") then
physics.setGravity(10,0)
end
end
boy.preCollision = onLocalPreCollision
boy:addEventListener( "preCollision", boy )
答案 0 :(得分:0)
尝试代码 你必须使用自我或事件
event.target是左或右对象
local left=display.newRect()
left.name=="left"
local right=display.newRect()
right.name="right"
physics.addBody("static",left)
physics.addBody("static",right)
local function onLocalPreCollision( self, event )
if (event.other.name == "left") then
physics.setGravity(-10,0)
end
if (event.other.name == "right") then
physics.setGravity(10,0)
end
end
boy.preCollision = onLocalPreCollision
boy:addEventListener( "preCollision", boy )