Jump to content

PIXI spritesheet loader with image name prefix


brean
 Share

Recommended Posts

Hi PIXI-community,

 

Let us assume we have 2 JSON-file based spritesheets (e.g. game.json and ui.json). Both have same names for some of their textures (e.g. "button-up-skin", "button-down-skin" etc. One sprite has the Button for the base game UI, the other one a clearer button for the level editor).

In the spritesheetParser the key used to store the texture in the TextureCache is the same for both, so whatever image loads second overrides the texture.

 

Can I access the texture somehow different then the global texture cache?

Can I get the image from the texture cache and save it somewhere else before the other image gets loaded?

Is there a way to prefix the name so they get both stored in the cache?

Or do I have to do something else (e.g. rename the textures in my spritesheet, extend spritesheetParser.js so it codes the name of the file loaded into the name of the texture)?

Link to comment
Share on other sites

Hey,

 

you can make sure that your frames names are unique at spritesheets export stage. In smaller to medium projects that's fine approach.

 

Otherwise create your own parser, and populate PIXI.utils.TextureCache the way you want. Just do not forget that nesting frames in "namespaces" will require overriding all fromFrame functions.

 

Marcin

Link to comment
Share on other sites

If you are using the loader, then just use the loader. As I mentioned here:

http://www.html5gamedevs.com/topic/14524-v3-access-cached-texture-by-name/

The loader already gives you access to everything you load, by the names you load it as. When you load your ui.json spritesheet you will be able to look in the ui.json resource and see a textures property with all the textures you loaded. Nothing makes you use the global TetureCache, it is just there for the silly convience .fromX() methods.

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...