我有一系列定义如下的圆形对象:
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碰撞在很大程度上是起作用的,但有时圆形物体会落在可移动的物体上,并滚动一小段时间,然后由碰撞检测来处理。
如何为碰撞提供更即时的效果?对象的属性是否需要不同,以便在碰撞上有更多的“力”?
发布于 2012-10-26 19:55:42
在气球上设置"isSensor“为"true”,这样就会触发你的碰撞功能,而不会发生颠簸、滚动等。
:)
https://stackoverflow.com/questions/13071357
复制相似问题