Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

07 | Cocos2D-JS | How to remove a sprite of screen #8

Open
Gurigraphics opened this issue Apr 29, 2018 · 0 comments
Open

07 | Cocos2D-JS | How to remove a sprite of screen #8

Gurigraphics opened this issue Apr 29, 2018 · 0 comments

Comments

@Gurigraphics
Copy link
Owner

Gurigraphics commented Apr 29, 2018

07 | How to remove a sprite of screen

Game.layers.js

Edit the Game.layers.js
To remove a sprite you need to add a sprite to a layer, and the layer to the game.

Here are four examples on how to remove the sprite.

    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
     
         var sprite = cc.Sprite.create("HelloWorld.png");
         sprite.setTag(1);
         sprite.setPosition(x,y);
         layer.addChild(sprite,0);  // add sprite to layer  
     
         setTimeout(function(){
             //layer.removeChild(sprite); // remove sprite of layer
             //layer.removeChildByTag(1); // remove sprite by tag
             //layer.removeAllChildren(); // remove all children
             //layer.removeFromParent(); // remove from parent
         }, 3000); // after 3 seconds
          
    }; 
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant