如何检测cocos2djs中两个圆圈之间的碰撞?

时间:2015-11-19 09:26:35

标签: javascript html5 cocos2d-js

我正在做一个类似于AA游戏的游戏,这是在游戏店里。我发现难以检测到两个球之间的碰撞..

for (var i = 0; i < mm.length; i++) {
    bw=ball._getWidth();
    bh=ball._getHeight();

    radi=Math.sqrt(((bw/2* bw/2)+ (bh/2 *bh/2)));

    gw=gg[n]._getWidth();
    gh=gg[n]._getHeight();

    rad=Math.sqrt(((gw/2* gw/2)+ (gh/2 *gh/2)));

    var c1Radius=rad;
    var c2Radius=radi;

    //gg[n] are the balls that are moved on a mouseclick      
    var ggn = gg[n].convertToWorldSpace(gg[n].getAnchorPoint());

    //mm[i] are the balls that are rotating 
    var mmi= mm[i].convertToWorldSpace(mm[i].getAnchorPoint());

    distX = mmi.x - ggn.x;
    distY = mmi.y - ggn.y;

    var magnitude1 = Math.sqrt(distX * distX + distY * distY);

    if( magnitude1 <c1+c2){
        val=1;
        clearInterval(interval);
        cc.eventManager.removeAllListeners();

        for (var i = 0; i < arr.length; i++) {
            arr[i].runAction(cc.repeatForever(cc.rotateBy(5000, 90, 90)));
        }
        for (var i =0; i < err.length; i++) {
            err[i].runAction(cc.repeatForever(cc.rotateBy(5000, 90, 90)));      
        }

        var ls=cc.sys.localStorage;
        var keww="eww";
        var daww=ls.getItem(keww);

        Leww=2;
        ls.setItem(keww,Leww);

        setTimeout(function () {
            cc.director.runScene(new HelloWorldScenefailed());
        },1000);
    }
}

如何检测正在旋转的对象与单击鼠标时移动的对象之间的碰撞?

0 个答案:

没有答案