Skip to content

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

@Gurigraphics

Description

@Gurigraphics

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions