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?