我有一系列圆形对象,定义如下:
local myBalloon = display.newImageRect("images/cracker.png", 20, 20);
myBalloon:setReferencePoint(display.CenterReferencePoint);
myBalloon.x = Random(50, _W-50);
myBalloon.y = (-10);
myBalloon.myName="balloon"
myBalloon.isSleepingAllowed = false;
physics.addBody(myBalloon, "dynamic", {density=3.0, friction=1.0, bounce=0.0, radius=9});
然后我有一个可移动的对象定义如下:
local threeWay = display.newImageRect("images/3way.png", 80, 43);
threeWay:setReferencePoint(display.CenterReferencePoint);
threeWay.x = (display.contentWidth / 2);
threeWay.y = (display.contentHeight -15);
threeWay.myName = "threeway"
pentagonShape = { -40,-5, 0,-22, 40,-5, 35,20, -35,20 }
physics.addBody(threeWay, "static", {density=4.0, friction=1.7, bounce=0.0, shape=pentagonShape});
我还为圆形物体设置了碰撞检测,如下所示:
function myBalloon:collision(e)
if (timeLeft ~= false) then
if (playerReady == true) then
if (e.phase == "ended") then
if ( e.other.myName == "threeway" ) then
audio.play(balloonPop);
removeBalloons(self);
end
end
end
end
end
大部分碰撞都起作用,但有时圆形物体将落在可移动物体上并在碰撞检测照射之前稍微向下滚动。
如何为碰撞提供更快速的效果? 对象的属性是否需要不同,因此碰撞时会有更多的“力”?
答案 0 :(得分:1)
在气球上放置“isSensor”为“true”,这样它会触发你的碰撞功能而不会碰撞,滚动等......
:)