Cocos2D-JS-Quick-Tutorials icon indicating copy to clipboard operation
Cocos2D-JS-Quick-Tutorials copied to clipboard

08 | Cocos2D-JS | How to extend the attributes of a sprite

Open Gurigraphics opened this issue 7 years ago • 0 comments

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);
        }
    });

Gurigraphics avatar Apr 29 '18 22:04 Gurigraphics