用H5与cocos-js结合编写的小游戏,见缝插针。
游戏截图
点击鼠标发射针,插在中间的球体当中进行旋转。
onTouchBegan:function(touch, event){
var target =event.getCurrentTarget();
if(target.playerBall.lenght<=0)
return;
var lastp=cc.p(0,0);
for(var i=0;i
var ball = target.playerBall[i];
if(i==0) {
lastp=ball.getPosition();
var bp = target.zx.convertToNodeSpace(cc.p(GC.w_2,target.zx.y - target.lenght));
ball.setPosition(bp);
ball.removeFromParent();
target.addBallInZX(ball);
}
else{
var nowp=ball.getPosition();
ball.runAction(cc.moveTo(0.1,lastp));
// ball.setPosition();
lastp=nowp;
}
}
target.playerBall.splice(0,1);
return true;
}
对游戏胜利和失败的检测
addBallInZX:function(coball){
this.allBall.push(coball);
this.zx.addChild(coball);
coball.scheduleUpdate();
this.zx.drawnode.drawSegment(cc.p(0, 0),cc.p(coball.x,coball.y), 1,cc.color(255, 255, 255, 255));
for(var i=0;i
var p=this.allBall[i].getPosition();
if(cc.pDistance(p,coball.getPosition())
this.gameOver(coball);
return;
}
}
if(this.playerBall.length<=1)
{
this.gameWin();
}
}
此游戏这俩点为重要的地方。