Jump to content

What is the correct way to use loaded JSON texture atlas?


Roygbiv
 Share

Recommended Posts

Hello,

I'm just stasting out with PIXI and making games in general as a hobby.
Now I followed the tutorial here: https://github.com/kittykatattack/learningPixi#creating-sprites-from-a-loaded-texture-atlas and it says there are three general ways to create a sprite from a texture atlas:  (edited a bit)

//1. Access the `TextureCache` directly 
dungeon = new Sprite(PIXI.utils.TextureCache["dungeon.png"]);

//2. Access the texture using the loader's `resources`:
explorer = new Sprite(    resources["images/treasureHunter.json"].textures["explorer.png"]  );
  
//3. Create an optional alias called `id` for all the texture atlas 
id = PIXI.loader.resources["images/treasureHunter.json"].textures; 
treasure = new Sprite(id["treasure.png"]);


Out of those three accessing the TextureCache directly seems the easiest to me, but I noticed that there are no errors if I mistype the texture's name. So that could couse alot of irritating issues sometimes. It has already coused some headaches.

the example here: https://pixijs.github.io/examples/#/basics/spritesheet.js uses yet another way to make use of the loaded textures:
// magically works since the spritesheet was loaded with the pixi loader
 [...]  PIXI.Texture.fromFrame('rollSequence00' + val + '.png');

This, I noticed DOES throw an error to the console if I mistype the name.

So PIXI.Texture.fromFrame seems to be the best way I have seen so far. But it's kinda confusing now, all these different ways.


Anyway, what's the correct way to use textures from a spritesheet loaded with a JSON file?


 

Link to comment
Share on other sites

  • 1 year later...
On 1/23/2017 at 7:32 PM, themoonrat said:

There is no correct way; as you've noted, there are options available to different circumstances. One that throws errors if the texture is not found is my personal preference. Since I'm not using the loader in my game, I therefore use PIXI.Texture.fromFrame.

Hi themoonrat, I'm curious as to why you're not using the loader. Is it that you use another package for loading, or is your game offline, or some other sneaky tricks?

Best Regards,

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