var HelloWorldLayer = cc.Layer.extend({
linelr:null,
circle2:null,
action2:null,
ctor:function () {
//////////////////////////////
// 1. super init first
this._super();
var size = cc.winSize;
var layerBackGround = new cc.LayerColor(cc.color(255,255,255,255),size.width,size.height);
//layer1.ignoreAnchorPointForPosition(false);
this.addChild(layerBackGround, 0);
this.linelr = new cc.DrawNode();
this.linelr.drawSegment( cc.p(10,400), cc.p(470, 400), 5, cc.color(40,120,240,100) );
this.addChild(this.linelr, 10);
this.circle2 = new cc.DrawNode();//灰色的在下方
this.circle2.retain();
this.circle2.x=120;
this.circle2.y=100;
this.circle2.drawDot( cc.p(this.circle2.x, this.circle2.y), 50, cc.color(0,0,0,100));
this.scheduleOnce(this.move,0);
this.scheduleUpdate();
return true;
},
move : function(){
this.action2 =new cc.MoveBy(3, cc.p(0, 400));
this.circle2.runAction(this.action2);
this.addChild(this.circle2, 10);
},
update : function()
{
var dollRect = this.linelr;
var dollHeadRect = this.circle2;
if(cc.rectIntersectsRect(dollRect,dollHeadRect))//碰撞检测
{
cc.director.getActionManager().removeAction(this.action2);//中止运行
//cc.director.getActionManager().pauseAllRunningActions();
}
}
});
var HelloWorldScene = cc.Scene.extend({
onEnter:function () {
this._super();
var layer = new HelloWorldLayer();
this.addChild(layer);
}
});
为什么不碰撞啊