Sign in to follow this  
StudioMaker

Texture sourceSize same as frame size?

Recommended Posts

How would i make the sourceSize (width and height) the same as the trimmed size when making a PIXI.Texture.from() ?

Because my sprite gets kinda messed up when the sourceSize is {w: 614, h: 564} and the trim is {width: 286, height: 481}, and i couldnt change the width and height on the texture directly either, soo not really sure.

Share this post


Link to post
Share on other sites

You have to edit it manually.
 

var baseTex = PIXI.BaseTexture.from(...);
var tex = new PIXI.Texture(baseTex, frame, orig, trim, 0);

As what is frame/orig/trim, you have to look in 
https://github.com/pixijs/pixi.js/blob/dev/packages/core/src/textures/Texture.js
https://github.com/pixijs/pixi.js/blob/dev/packages/spritesheet/src/Spritesheet.js#L196

https://github.com/pixijs/pixi.js/blob/dev/packages/sprite/src/Sprite.js#L261

Yes, I can give you some wise words about meaning of those rects: "frame" is what is in atlas, "orig" is what was original image (0,0,w,h), "trim" is that "frame" inside "orig": (x,y,w2,h2) - must fit inside orig. However its easy to mistake in parsing that explanation, so you have to look in the sources :)

Share this post


Link to post
Share on other sites

Ok thanks for the help! Ended up making something like this 

 

var b = PIXI.Texture.from(t.frames.index[t.i])
, n = new PIXI.Texture(b, new PIXI.Rectangle(b.frame.x, b.frame.y, b.frame.width, b.frame.height))

 

Which seems to work perfectly fine. :)

Share this post


Link to post
Share on other sites

yes, single "frame" is enough. If you need more then you need to pass two more rects. That also looks like cloning, you'll get same texture. Don't forget that when you modify it later, like "n.frame.x+=1", you'll have to do "n.updateUvs()" to notify texture that something inside was changed.

Welcome to the forums!

Edited by ivan.popelyshev

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.

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...
Sign in to follow this  

  • Recently Browsing   0 members

    No registered users viewing this page.