StudioMaker Posted January 2, 2020 Share Posted January 2, 2020 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. Quote Link to comment Share on other sites More sharing options...
ivan.popelyshev Posted January 2, 2020 Share Posted January 2, 2020 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.jshttps://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 Quote Link to comment Share on other sites More sharing options...
StudioMaker Posted January 2, 2020 Author Share Posted January 2, 2020 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. Quote Link to comment Share on other sites More sharing options...
ivan.popelyshev Posted January 2, 2020 Share Posted January 2, 2020 (edited) 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 January 2, 2020 by ivan.popelyshev 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.