Jambutters Posted November 13, 2017 Share Posted November 13, 2017 let app = new PIXI.Application({ autoStart: true, width: 640, height: 480 }); PIXI.loader.resoures.add("./spritesheet.json"); /* creates a Texture using the ENTIRE spirtesheet image instead of reading from json and cropping it to texture atlas */ let testTexture = new PIXI.Texture(PIXI.loader["./spritesheet.json"].textures["player2.png"]); //work around : new PIXI.Texture(PIXI.loader["./spritesheet.json"].textures["player2.png"],PIXI.loader["./spritesheet.json"].textures["player2.png"].orig); or by using .frame /* What's the point of passing ["player2.png"], specifying the texture atlas location if it's just going to use the entire image when creating calling new PIXI.Texture . */ let testSprite = new PIXI.Sprite(testTexture); /* this corrects the sprite with the correct frames though referencing the texture in the loader*/ let testTexture2 = PIXI.loader["./spritesheet.json"].textures["player2.png"].texture; let testSprite2 = new PIXI.Sprite(testTexture2); //correct crop refferencing texture atlas frame. I know how to work around this but shouldn't "new PIXI.Texture" reach into the json file and grab the correct location of the image rather than use the entire image of the spritesheet? Quote Link to comment Share on other sites More sharing options...
ivan.popelyshev Posted November 13, 2017 Share Posted November 13, 2017 Its "loader.resources['something']` , not just `loader['something']` . Whenever you ask pixi to load spritesheet under some `name`, it loads full texture in `name_image`, so `loader.resources['name_image'].texture` has full texture, while `loader.resources['name'].textures` has spritesheet textures, look here: https://github.com/pixijs/pixi.js/blob/dev/src/loaders/spritesheetParser.js#L9 Your workaround doesnt work because you dont specify correct frame, you have to pass something like `new PIXI.Rectangle(0,0,baseTexture.width, baseTexture.height)` where `baseTexture` is .. why am i explaining it? Please read the docs and use search on "PIXI.Texture" on this subforum to understand how it works. Better, just look in pixi sources, https://github.com/pixijs/pixi.js , its not a blackbox, you're supposed to read how pixi works if you want to use it seriously. 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.