Jump to content

Occassional Base Texture Oddity When Changing Sprite Texture


NerdyElf
 Share

Recommended Posts

Okay, I have a peculiar issue. I'm trying to edit a particular sprite that will change it's image AND the atlas it uses. I have like six atlases, each of which focuses on different things (like Characters, Blocks, etc).

However, the editor has a bunch of tiles that can be part of any of those atlases. So when I overwrite a tile, I need to also tell it which atlas to change to.

Theoretically, not too much of a problem. As far as I can tell, PIXI allows this with a fairly straightforward technique:

sprite.texture.baseTexture = getSheet( atlasGroup );
sprite.texture = PIXI.Texture.from(frameName);

getSheet( atlasGroup: AtlasGroup ) {
    return this.loader.resources[atlasGroup].textures;
}

However, when I do this, it's actually misbehaving. It's almost like other tiles are suddenly having their baseTexture changed as well, which makes me suspect there's some things being changed by reference. Which isn't a problem, but I need a way to change *only* the sprite's atlas.

TLDR: How do I change a sprite's atlas AND frame name in the correct way, without causing any by-reference texture updates that can affect other tile rendering?

 

Link to comment
Share on other sites

Actually, a fluke test may have just shed some light on this. I was temporarily commenting out the baseTexture change just to avoid the bug, and it seems like it transferred between atlases automatically.

So am I correct in thinking that all frame names are stored across all atlases, and will automatically assign the appropriate one? Thus also meaning that frame names would have to be unique per atlas?

Link to comment
Share on other sites

"textures" hashmap is not a magic object, its just collection of textures by names that no one changes after loading.

Of course, if oyu dont make copies of certain texture - all sprites with that texture will use different baseTexture :)

I implemented many hacks on texture frames and basetextures, and I didnt yet port my pixi-super-atlas plugin to v5. Its not a hard problem, not on the level of custom filters, but not an easy one too.

However one of things i remember is that baseTexture change sometimes doesnt result in proper sprite change, we fixed it some time ago, i advice you to use dev version: pixijs.download/dev/pixi.js (pixi-legacy.js is also there)

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