Skip to content

Commit

Permalink
Fix: changing tiling sprite anchor not updating view (pixijs#10513)
Browse files Browse the repository at this point in the history
* - optimise remove child
- change the way render group is stored
- added parentRenderGroup
- renderGroup now the owned render group

* remove dead code

* optimise destroy remove children

* optimise the rendergroup

* fix test import

* finak clean up

* fix parent issue

* final tweaks
update tests tio be more readable

* lint

* fix tiling sprite anchor

---------

Co-authored-by: Zyie <[email protected]>
  • Loading branch information
GoodBoyDigital and Zyie authored May 14, 2024
1 parent da12bce commit b91b6ac
Show file tree
Hide file tree
Showing 4 changed files with 32 additions and 1 deletion.
5 changes: 5 additions & 0 deletions src/scene/container/container-mixins/effectsMixin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,11 @@ export const effectsMixin: Partial<Container> = {
renderGroup.structureDidChange = true;
}

// if (this.renderGroup)
// {
// this.renderGroup.structureDidChange = true;
// }

this._updateIsSimple();
},
/**
Expand Down
9 changes: 8 additions & 1 deletion src/scene/sprite-tiling/TilingSprite.ts
Original file line number Diff line number Diff line change
Expand Up @@ -196,7 +196,14 @@ export class TilingSprite extends Container implements View, Instruction

this.allowChildren = false;

this._anchor = new ObservablePoint(this);
this._anchor = new ObservablePoint(
{
_onUpdate: () =>
{
this.onViewUpdate();
}
},
);

this._applyAnchorToTexture = applyAnchorToTexture;

Expand Down
17 changes: 17 additions & 0 deletions tests/renderering/sprite/TilingSprite.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -185,4 +185,21 @@ describe('TilingSprite', () =>
expect(tilingSprite.texture).toEqual(Texture.EMPTY);
});
});

describe('Anchor', () =>
{
it('should update anchor', () =>
{
const texture = new Texture();
const sprite = setup({ texture });

expect(sprite.texture).toEqual(texture);

const spy = jest.spyOn(sprite, 'onViewUpdate');

sprite.anchor.x = 0.5;

expect(spy).toHaveBeenCalledTimes(1);
});
});
});
2 changes: 2 additions & 0 deletions tests/scene/scene.tests.ts
Original file line number Diff line number Diff line change
Expand Up @@ -578,6 +578,8 @@ describe('Scene', () =>

compareUpdateList([child], container.renderGroup, 1);

expect(true).toBeTrue();

// console.log(container2.layerGroup.childrenToUpdate[1])
// expect(container2.layerGroup.childrenToUpdate[1]).toEqual({
// list: [child2, child3],
Expand Down

0 comments on commit b91b6ac

Please sign in to comment.