设置好打靶图片和准心的图片。设置点击的时候发射子弹,并发射子弹的时候出现效果并移除
sheji:function(touch){
var s = touch.getLocation();
var pic3 = new cc.Sprite(res.pic_3)
pic3.setPosition(s);
this.addChild(pic3);
setTimeout(function(){
pic3.removeFromParent()
},1000)
},
判断点击打靶的时候多少分数,定义打靶圆心的位置设置一个全局变量
circle:null,
在点击的地方输出圆心点击位置
onTouchBegan:function(touch, event){
cc.log(touch.getLocation())
return true;
},
定义好圆心的坐标
this.circle = cc.p(400,230);
然后根据圆心的位置来设置范围来规定分数
_biaoji:function(touch){
var dise = cc.pDistance(touch.getLocation(),this.circle)
if(dise>=0 && dise<=30){
this.dis = "A";
}else if(dise>=30 && dise<=60){
this.dis = "B";
}else if(dise>=60 && dise<=90){
this.dis = "C";
}else if(dise>=90 && dise<=120){
this.dis = "D";
}else if(dise>=120 && dise<=150){
this.dis = "E";
}else{
this.dis = "F";
}
switch(this.dis){
case "A":
this.make.string = "100";
cc.log("我进来了。。。。")
break;
case "B":
this.make.string = "75";
break;
case "C":
this.make.string = "50";
break;
case "D":
this.make.string = "25";
break;
case "E":
this.make.string = "10";
break;
case "F":
this.make.string = "0";
break;
}
}