2

次のように定義された一連の丸いオブジェクトがあります。

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

衝突はほとんどの部分で機能しますが、場合によっては、丸いオブジェクトが移動可能なオブジェクトに着地し、衝突検出によって処理される前に少しロールダウンします。

衝突に対してより瞬間的な効果を提供するにはどうすればよいですか?衝突により多くの「力」がかかるように、オブジェクトの属性を変える必要がありますか?

4

1 に答える 1

1

バルーンに「isSensor」を「true」として配置します。これにより、ぶつかったり、転がったりすることなく、衝突関数がトリガーされます。

:)

于 2012-10-26T11:55:41.523 に答える