您的位置:首页 > 其它

三消模块出现随机的办法

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)},})
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: