我想做连连看的效果
页面加载的时候能判断当前节点是哪个 ,下次点击的时候会输出下次的节点名字,我如果判断这2个节点一样,从而使这2个节点消除
game.js是加载在canvas上的插件,bgPrefab是红色背景预制模板aabbcc分别是连连看的小图;
以下是game.js:
cc.Class({
extends: cc.Component,
properties: {
bgPrefab: {
default: null,
type: cc.Prefab
},
draw: {
default: null,
type: cc.Node
},
imgWidth:58,
imgHeight:52,
},
// use this for initialization
onLoad: function () {
var x1;
var y1;
this.addMouse();
},
// called every frame, uncomment this function to activate update callback
update: function (dt) {
},
newredbg: function(x1,y1) {
var newbg = cc.instantiate(this.bgPrefab);
this.node.addChild(newbg);
newbg.setPosition(x1,y1);
},
removeBg:function(){
//console.log(this.node.children);
this.node.children[this.node.children.length-1].destroy();
},
addMouse:function(){
var imgWidth=this.imgWidth;
var imgHeight=this.imgHeight;
this.node.on('touchstart', function (event) {
var x1= event.getLocationX()-480;
var y1= event.getLocationY()-320;
if(this.node.children[this.node.children.length-1].name!="bg"){
if(x1>-imgWidth/2&&x1<imgWidth/2&&y1>-imgHeight/2&&y1<imgHeight/2){
this.newredbg(0,0);
console.log(this.node.name);
}
else if(x1>-imgWidth/2&&x1<imgWidth/2&&y1>imgHeight/2&&y1<imgHeight*3/2){
this.newredbg(0,imgHeight);
}
else if(x1>-imgWidth/2&&x1<imgWidth/2&&y1>-imgHeight*3/2&&y1<-imgHeight/2){
console.log(imgHeight);
this.newredbg(0,-imgHeight);
}
else if(x1>-(imgWidth)*3/2&&x1<-imgWidth/2&&y1>-imgHeight/2&&y1<imgHeight/2){
this.newredbg(-imgWidth,0);
}
else if(x1>-(imgWidth)*3/2&&x1<-imgWidth/2&&y1>imgHeight/2&&y1<imgHeight*3/2){
this.newredbg(-imgWidth,imgHeight);
}
else if(x1>-(imgWidth)*3/2&&x1<-imgWidth/2&&y1>-imgHeight*3/2&&y1<-imgHeight/2){
this.newredbg(-imgWidth,-imgHeight);
}
}else{
this.removeBg();
}
}, this);
},
});