Corona - 碰撞检测

我有一系列的圆形物体,定义如下:

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

碰撞检测基本工作,但有时圆形物体会落在可移动物体上并滚动一小段时间,然后才被碰撞检测处理。

如何提供更即时的碰撞效果? 需要使物体的属性不同,以便在碰撞时有更多的“力”吗?

点赞
用户269870
用户269870

将“isSensor”设为“true”在气球上,这样它会触发你的碰撞函数,而不会撞到,滚动等... :)

2012-10-26 11:55:41