Jump to content

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.


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

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.

Link to comment
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

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

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.

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.


  • Recently Browsing   0 members

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