Jump to content

Need help! I have a bug with cacheAsBitmap = true


vdddslep
 Share

Recommended Posts

Hi, friends 

I am working on the game where I have more than 10 thousand objects in 9 different layers on the scene. 

Thank God that I can easily cache it, to do that I split each layer up into small pieces, I called them chunks.
 

So, I cached each chunk using cacheAsBitmap = true and everything was great, until I changed the scene.

Of course, I recached the chunk: 

let chunk:PIXI.Container = this.chunkGrid[chunkPosition.x][chunkPosition.y];
if (chunk.cacheAsBitmap) {
    chunk.cacheAsBitmap = false;
}
if(chunk.width > 0 && chunk.height > 0) {
    chunk.cacheAsBitmap = true;
}

But after I do it, chunk position is changing (See the screenshot).
I have no idea why and how could I deal with it 

I'll be appreciate for any help

Best regards,

Denis 

bug.png

Link to comment
Share on other sites

According to https://github.com/pixijs/pixi.js/blob/dev/src/extras/cacheAsBitmap.js#L173 its not snapping the coords, and that's part of the problem. If we somehow ensure that localbounds are integers, filtering bug will go away. As for other, i dont know yet :)

I created an issue: https://github.com/pixijs/pixi.js/issues/4170

Link to comment
Share on other sites

As I understand localbounds is not integers because I use

this.cannonClip.anchor.set( 0.5, 0.3);

despite the fact that sizes of all textures are power of 2 after using anchor.set localbounds becomes not integers.

So, how can I set the anchor to keep localbounds integers?

 

Link to comment
Share on other sites

Looks like it works for me as a workaround: 

getLocalBounds(rect?: PIXI.Rectangle): PIXI.Rectangle {
    let bounds:PIXI.Rectangle = super.getLocalBounds(rect);
    return new PIXI.Rectangle(Math.round(bounds.x), Math.round(bounds.y), Math.round(bounds.width), Math.round(bounds.height));
}

If I put it to the Chunk class.

Thank you for your collaboration, without it I would never found it. 

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