Legomite Posted August 24, 2015 Share Posted August 24, 2015 Is there a way to delete a sprite? Quote Link to comment Share on other sites More sharing options...
Raiper34 Posted August 24, 2015 Share Posted August 24, 2015 sprite.destroy() ???? Or I completelly do not understand? :-D Quote Link to comment Share on other sites More sharing options...
zakhov Posted August 24, 2015 Share Posted August 24, 2015 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); Quote Link to comment Share on other sites More sharing options...
LinkTree Posted August 24, 2015 Share Posted August 24, 2015 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 Quote Link to comment Share on other sites More sharing options...
Legomite Posted August 28, 2015 Author Share Posted August 28, 2015 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 - 3But the code does not work! I tried calling game.scene.chunkList[0] by itself, but it does not seem to exist. Please help! Quote Link to comment Share on other sites More sharing options...
LinkTree Posted August 29, 2015 Share Posted August 29, 2015 How did you define game.scene.chunkList? if you try to call game.scene.chunkList[0] and it returns undefined it means you didn't define it properly. Quote Link to comment Share on other sites More sharing options...
Legomite Posted August 29, 2015 Author Share Posted August 29, 2015 How did you define game.scene.chunkList? if you try to call game.scene.chunkList[0] and it returns undefined it means you didn't define it properly.Code I used. Quote Link to comment Share on other sites More sharing options...
LinkTree Posted August 29, 2015 Share Posted August 29, 2015 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. Quote Link to comment Share on other sites More sharing options...
Legomite Posted August 30, 2015 Author Share Posted August 30, 2015 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 {} Quote Link to comment Share on other sites More sharing options...
Legomite Posted August 30, 2015 Author Share Posted August 30, 2015 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); Quote Link to comment Share on other sites More sharing options...
LinkTree Posted August 30, 2015 Share Posted August 30, 2015 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. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
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.