Roygbiv Posted January 23, 2017 Share Posted January 23, 2017 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? Quote Link to comment Share on other sites More sharing options...
themoonrat Posted January 23, 2017 Share Posted January 23, 2017 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. Quote Link to comment Share on other sites More sharing options...
ironchestgames Posted August 21, 2018 Share Posted August 21, 2018 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, Quote Link to comment Share on other sites More sharing options...
Recommended Posts
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.