Jump to content

Delete sprite?


Legomite
 Share

Recommended Posts

In addition to zakhov's answer, if you want to completely remove an asset of a sprite from the memory you can do so like this:

game.removeAsset('logo.png'); // Remove sprite from memorygame.removeAsset('sprites.json'); // Remove sprite sheet from memorygame.removeAssets(); // Remove all assets from memorygame.system.setScene('Game', true); // Change scene and remove all assets from memory
Link to comment
Share on other sites

Depending on how you implemented the sprite to your scene,

game.scene.container.removeChild(this.sprite);//replace container with container name you used to add the sprites//orthis.parent.removeChild(this.sprite);  

I added a sprit into a container, and tried removing it via event.

this.sprite.click = this.sprite.tap = function(event) {    game.scene.chunkList[this.blockData.chunk].removeChild(this);    }
ChunkList is defined 0 - 3 so

chunkList[0] = new game.Container();
I defined this.blockData.chunk so it will be 0 - 3

But the code does not work! I tried calling game.scene.chunkList[0] by itself, but it does not seem to exist. Please help!

Link to comment
Share on other sites

In the code above I don't see you adding the object chunkList into game.scene as a property of it. So when you call game.scene.chunkList in your event handler it has no idea what you refer to.

On a different note, why did you decide to define chunkList as an object instead of an array? Not that it's wrong, they both have their own merits. I just wonder what's the reasoning behind this decision.

Link to comment
Share on other sites

In the code above I don't see you adding the object chunkList into game.scene as a property of it. So when you call game.scene.chunkList in your event handler it has no idea what you refer to.

On a different note, why did you decide to define chunkList as an object instead of an array? Not that it's wrong, they both have their own merits. I just wonder what's the reasoning behind this decision.

Oh! I confuse [] and {} a lot. I'm still new to {}
Link to comment
Share on other sites

In the code above I don't see you adding the object chunkList into game.scene as a property of it. So when you call game.scene.chunkList in your event handler it has no idea what you refer to.

On a different note, why did you decide to define chunkList as an object instead of an array? Not that it's wrong, they both have their own merits. I just wonder what's the reasoning behind this decision.

This does not appear to work.

chunkList.addTo(game.scene.stage);

Link to comment
Share on other sites

This does not appear to work.

chunkList.addTo(game.scene.stage);

to add cunkList as a property of game.scene (or any other object for that matter) you do game.scene.chunkList = chunkList.

chunkList has no addTo method of it's own so you can't call chunkList.addTo unless you defined that method. Further more addTo of the game engine objects only adds objects as children(adds them into a property called children that contains a list in an Array format) and doesn't add them as a property on their own.

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...