三消中消除,移动代码.
来源:互联网 发布:淘宝组装机便宜的原因 编辑:程序博客网 时间: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
- 三消中消除,移动代码.
- 消除重复代码
- 如何消除重复代码
- 消除viewport的疑惑-移动网页开发
- 移动click消除300毫秒及摇一摇
- 消除重复代码的方法
- 消除页面缓存的代码
- 消除重复代码的意义
- 消除博客中的代码行号
- Lombok—消除样板代码
- 使用#include消除重复代码
- C++编译重复代码消除
- 消除Java 的冗余代码
- 消除C++中警告代码
- Speex回声消除代码分析
- 使用样式消除重复代码
- Speex回声消除代码分析
- lombok注解消除臃肿代码
- lua热更新都能更新什么
- Fragment的生命周期
- 分页查询优化
- Maven3.0+Spring MVC4+Spring 4+Mybatis3+junit4
- 断点续传的原理
- 三消中消除,移动代码.
- 18118 勇者斗恶龙
- 如何默认打开user版本 debug 选项, 默认打开adb 连接
- win10安装64位Apache2.2.31
- 添加动画、单张图片
- java获取系统时间日期
- MySQL 多实例详解
- Android DiskLruCache
- DAY2-单片机入门必备