三消模块出现随机的办法
2016-06-30 13:35
232 查看
利用创建一个精灵来随机显示图片.
var GameData ={
W_NUM:8, H_NUM:8, } var HelloWorldLayer = cc.Layer.extend({ sp:null, ctor:function(){ this._super(); this._init() }, _init:function(){ var arr = [] for(var i =0 ;i<GameData.W_NUM;i++){ arr [i] = [] for(var j =0 ;j<GameData.H_NUM;j++){ this.sp =new Cell() this.sp.setPosition(200+(40*i),cc.winSize.height-20-(40*j)) this.addChild(this.sp) this.sp.setArrIndex(i,j) } } } }); var HelloWorldScene = cc.Scene.extend({ onEnter:function () { this._super(); var layer = new HelloWorldLayer(); this.addChild(layer); } });
var Cell= cc.Sprite.extend({type:0,ctor:function(){this._super();this._init()},_init:function(){this.type =parseInt(1+Math.random()*4);this.initWithFile("res/pic"+this.type+".png")},setArrIndex:function(i,j){var labei =new cc.LabelTTF(i+","+j,"",10)labei.enableStroke(cc.color(0,0,0,255),1)labei.setPosition(10,10)this.addChild(labei)},})
相关文章推荐
- H.264视频在android手机端的解码与播放(转)
- Html-知识点总结
- word 字符串参量过长 解决
- 双向链表的建立
- Avoiding Buffer Overruns
- maven向本地仓库导入官方仓库没有的jar包
- 复旦大学2015--2016学年第二学期(15级)高等代数II期末考试第六大题解答
- leadJS初构建
- Android Button自动触发点击事件
- Linux中启动和停止jar包的运行
- Android之对话框AlertDialog及其子类的使用(二)
- Javascript中单击按键来循环改变字体的颜色
- 如何查看一个进程中的某个线程是否存活?
- Android实现不重复启动APP的方法
- crontab
- adb 使用的一点命令
- Jquery基本选择器总结
- Maven 手动添加 JAR 包到本地仓库
- GDB(十)--调试正在运行的进程
- mvc5+ef6+Bootstrap 项目心得--身份验证和权限管理