三消中消除,移动代码.

来源:互联网 发布:淘宝组装机便宜的原因 编辑:程序博客网 时间:2024/05/12 08:57
var GameData ={    W_NUM:8,    H_NUM:8,}var HelloWorldLayer = cc.Layer.extend({    jiehsou: null,   sp:null,    arr:null,    ctor:function(){        this._super();        this._init()        var that = this        cc.eventManager.addCustomListener("diaoluo",function(event){            that.jiehsou = event.getUserData()            cc.log("xiabiaio", that.jiehsou.x,that.jiehsou.y)            var i = that.jiehsou.x            for(var j = that.jiehsou.y - 1; j >= 0; j--){                if(that.arr[i][j] == null)                continue;                that.arr[i][j].fallDown()                var a = that.arr[i][j].arrIndex                that.arr[a.x][a.y] = that.arr[i][j]                that.arr[i][j] = null            }        })    },    _init:function(){        this.arr = []        for(var i =0 ;i<GameData.W_NUM;i++){          this.arr [i] = []            for(var j =0 ;j<GameData.H_NUM;j++){                this.sp = new Cell(i,j)                this.sp.setPosition(200+(40*i),cc.winSize.height-20-(40*j))                this.addChild(this.sp)                this.sp.setArrIndex(i,j)                this.arr[i][j] = this.sp            }        }},});var HelloWorldScene = cc.Scene.extend({    onEnter:function () {        this._super();        var layer = new HelloWorldLayer();        this.addChild(layer);    }});
精灵类
var Cell= cc.Sprite.extend({    type:0,    listener1:null,    i: null,    j: null,    arrIndex: null,    labei: null,    ctor:function(i , j) {        this._super();        this.j = j;        this._init()        this._lear()        this.scheduleUpdate()        this.arrIndex = {            x: i,            y: j,        }    },    update: function (){        this.labei.setString(this.arrIndex.x+","+this.arrIndex.y,"",10)    },    _init:function(){        this.type =parseInt(1+Math.random()*4);        this.initWithFile("res/pic"+this.type+".png")    },    setArrIndex:function(i,j){        this.labei =new cc.LabelTTF(i+","+j,"",10)        this.labei.enableStroke(cc.color(0,0,0,255),1)        this.labei.setPosition(10,10)        this.addChild(this.labei)    },    fallDown: function(){        var move = cc.moveBy(2, 0, -40)        this.runAction(move)        this.arrIndex.y++    },    _lear:function(){        var that = this;         this.listener1 = cc.EventListener.create({            event: cc.EventListener.TOUCH_ONE_BY_ONE,            swallowTouches: true,            onTouchBegan: function (touch, event) {                var target = event.getCurrentTarget()                var locationInNode = target.convertToNodeSpace(touch.getLocation());                var s = target.getContentSize()                    var rect = cc.rect(0, 0, s.width, s.height)                    if (cc.rectContainsPoint(rect, locationInNode) ) {                        that.removeFromParent(true)                        cc.eventManager.dispatchCustomEvent("diaoluo", that.arrIndex)                    }            },            onTouchMoved: function (touch, event) {            },            onTouchEnded: function (touch, event) {            }        })        cc.eventManager.addListener(this.listener1, this)    }})


0 0
原创粉丝点击