我有一系列定义如下的圆形对象:
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
碰撞在很大程度上起作用,但有时圆形物体会落在可移动物体上并滚下一点,然后才被碰撞检测处理。
如何为碰撞提供更即时的效果?物体的属性是否需要不同以便碰撞有更多的“力”?