amshegarh

Best way to trim texture

Recommended Posts

I've seen this question before, has anything changed? I need to get texture(s) from spritesheet, sometimes texture needs to be cut in several ones and placed in different sprites, previous answer only took texture from img src and it was something more complicated than it should be for task this simple

Share this post


Link to post
Share on other sites

still "new PIXI.Texture(baseTexture, frame, trim, orig, rotate)". Frame is obvious, but sometimes you need extra stuff,  and i cant explain other params in this thread, look in the docs. After 2-3 fails you'll get it :)

I dont know how to make it easier. If you want to make it even easier - propose an API for it. Yes, sometimes in private code I use methods that actually cut texture region to more texture regions, for example for NineSlice or to sort objects in isometry and cut sprites with multiple vertical lines. This is one of such attempts for pixi-v4: https://github.com/gameofbombs/pixi-heaven/tree/master/srcOld/base/atlas  but it doesnt have nor good API's nor docs.

Share this post


Link to post
Share on other sites

Ok there is a problem, when i try to refer to base texture of a texture in spritesheet in such fashion

PIXI.Loader.shared.resources["spritesheet"].spritesheet.textures["Image144.png"].baseTexture

returned base texture is in fact of the whole spritesheet, but i need base texture of a single texture in spritesheet

How do i do that

Share this post


Link to post
Share on other sites

ok, you have frame of original texture in that baseTexture, right? consider it frame1. you want to trim it, frame2. Resulting frame will be "(frame1.x + frame2.x, frame1.y + frame2.y, frame2.width, frame2.height)" . That's the problem i talked about - that basic addition of frames does not exist in pixi. You have to use your programming skills on it :) PixiJS doesnt have to do everything for you . If that info is not enough, i can make demo in weekend.

In my case it was like that: https://github.com/gameofbombs/pixi-heaven/blob/master/srcOld/base/atlas/TextureRegion.ts#L17 , but you cant just ctrl+c that code, because i used extra fields for my atlas.

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

  • Recently Browsing   0 members

    No registered users viewing this page.