Cocos2D-JS-Quick-Tutorials
Cocos2D-JS-Quick-Tutorials copied to clipboard
08 | Cocos2D-JS | How to extend the attributes of a sprite
08 | How to extend the attributes of a sprite
Game.layers.js
Edit the Game.layers.js
Game.layers[1].extend = cc.Layer.extend({
init: function () {
this._super();
var game = this;
Game.layers[1].start( game );
}
});
Game.layers[1].start = function( game ){
var size = cc.director.getWinSize();
layer = cc.LayerColor.create(new cc.Color(0,0,0,250), 960, 640); // R+G+B+Opacity+X+Y
game.addChild(layer); // add layer to game
sprite = new sprite2();
sprite.setPosition(50,50);
sprite.setTag(1);
layer.addChild(sprite,0);
};
var sprite2 = cc.Sprite.extend({
ctor:function() {
this._super();
this.initWithFile("HelloWorld.png");
this.setScale(0.5);
}
});