shashank

Remove SpriteSheet TextureCache

Recommended Posts

I have loaded SpriteSheet using json. Like this below.

const loader = new PIXI.loaders.Loader();
loader.add('bunny', 'data/bunny.png')
      .add('spaceship', 'assets/spritesheet.json');
loader.load((loader, resources) => {

});

I want to remove all the TextureCache which was loaded using this spritesheet.json only.

I have tried.

PIXI.Texture.removeFromCache("spaceship");
PIXI.Texture.removeTextureFromCache("spaceship");

But in PIXI.TextureCache names of all the spriteFrame were included there. And still i am able to use image form frame. Using this.

var bgSprite2 = PIXI.Sprite.fromFrame("ship1");
bgSprite2.anchor.set(0.5, 0.5);
var pos = {x: 300, y: 200};
bgSprite2.position.set(pos.x, pos.y);
stage.addChild(bgSprite2);

I want to remove all the entries of spriteFrame in TextureCache and i want to load new set of spriteFrame.

I am doing this because i have spritesheet animations of two diffrent spaceship but the individual symbol name of both spaceship are same.

Please help.

Share this post


Link to post
Share on other sites

I hate cache problems, pixi cache is not  user-friendly

You have to understand that "remove from cache", "free the videomemory" arel different things, and "destoy the texture" includes all of them. There's also huge difference between Texture and BaseTexture. Make sure you understand all of it before you write that code.

You have to iterate through all textures of that spritesheet and remove them from cache, then remove baseTexture:

let baseTex = null;
for (key in spaceship.textures) {
    Texture.removeFromCache(spaceship.textures[key]); //or just 'key' will work in that case
    baseTex = spaceship.textures[key].baseTexture; //they all have same base texture
}
BaseTexture.removeFromCache(baseTex);

Also make sure you remove it from loader, just remove all things : `loader.reset()` or remove "spaceship" and "spaceship_image" from resources list.

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

  • Recently Browsing   0 members

    No registered users viewing this page.