Sign in to follow this  

new PIXI.Texture from spritesheet uses the entire spritesheet

Recommended Posts

let app = new PIXI.Application({ autoStart: true, width: 640, height: 480 });


/* 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? 

Share this post

Link to post
Share on other sites

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:

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, , its not a blackbox, you're supposed to read how pixi works if you want to use it seriously.

Share this post

Link to post
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.

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.

Sign in to follow this  

  • Recently Browsing   0 members

    No registered users viewing this page.