lars Posted May 11, 2020 Share Posted May 11, 2020 Hi All I'm trying to setup a spritesheet like this: this.myLoader = new PIXI.Loader(); this.myLoader .add("images","assets/images/props.png") .add("json","assets/images/props.json") .load(startGame()); function startGame(){ let spritesheetPropsTexture = PIXI.Texture.from("assets/images/props.png"); let spritesheetPropsSprite = new PIXI.Sprite(spritesheetPropsTexture); let mySheet = new PIXI.Spritesheet(spritesheetPropsSprite.texture.baseTexture,"assets/images/props.json"); let cheese = new PIXI.Sprite(myspritesheet.textures["cheese.png"]); } I know that it´s fairly simpel like this: let sheet = PIXI.Loader.shared.resources["assets/images/props.json"].spritesheet; let cheese = new PIXI.Sprite(sheet.textures["cheese.png"]); with the shared loader. But i need to have a reference to the image. Anyone knows how to solve this. Quote Link to comment Share on other sites More sharing options...
lars Posted May 11, 2020 Author Share Posted May 11, 2020 It´s working now ? let spritesheetPropsTexture = PIXI.Texture.from(this.asset.get("images/props.png")); let spritesheetPropsSprite = new PIXI.Sprite(spritesheetPropsTexture); this.mySheet = new PIXI.Spritesheet(spritesheetPropsSprite.texture.baseTexture, this.imagePropsJson); this.mySheet.parse((textures) => { let cheese = new PIXI.Sprite(this.mySheet.textures["antenne.png"]); cheese.x = 200; cheese.y = 200; this.scene.addChild(cheese); }) "this.asset.get" is just my own reference to files. The only thing i had to change was: this.mySheet.parse((textures) => { Her goes my spritesheets }) Quote Link to comment Share on other sites More sharing options...
ivan.popelyshev Posted May 11, 2020 Share Posted May 11, 2020 just a tip : if there are less than 1000 (or 10000, i dont remembr) textures - that thing is not async, you can omit callback and do stuff just after you call parse() Quote Link to comment Share on other sites More sharing options...
lars Posted May 11, 2020 Author Share Posted May 11, 2020 Thank´s ... I will remember that ? Quote Link to comment Share on other sites More sharing options...
ivan.popelyshev Posted May 11, 2020 Share Posted May 11, 2020 You dont have to remember that, its better to clone pixi sources, open them in separate IDE window and search for classes when you use them. That way you can find something like that : https://github.com/pixijs/pixi.js/blob/4590b0b5ed156c731e4041940c587d78480d7e84/packages/spritesheet/src/Spritesheet.ts#L203 , modify your code and forget about it 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.