Jump to content

new PIXI.Texture from spritesheet uses the entire spritesheet


Jambutters
 Share

Recommended Posts

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? 

Link to comment
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: 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.

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

Guest
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.

Loading...
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...