Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Reset a point light that has a body takes a lot of time #5934

Closed
x-wk opened this issue Dec 2, 2021 · 2 comments · Fixed by #5936
Closed

Reset a point light that has a body takes a lot of time #5934

x-wk opened this issue Dec 2, 2021 · 2 comments · Fixed by #5936

Comments

@x-wk
Copy link

x-wk commented Dec 2, 2021

Version

  • Phaser Version: 3.55.2
  • Operating system: Win10
  • Browser:

Description

First create a static group, and add a lot of PointLight, and then calling 'body.reset', the time consumed is increasing as the number of calls increases. I don't know if this is the correct usage!

Example Test Code

create(){
      const group = this.physics.add.staticGroup();

      for (let i = 0; i < 20; i++) {
         for (let j = 0; j < 20; j++) {
            const p = new PointLight(this, i * 40 + 100, j * 40 + 100, 0xff0000, 20, Math.random())
               .addToDisplayList();
            group.add(p);
         }
      }

    const pl = new PointLight(this, 20, 20, 0xff0000, 20, 1)
         .addToDisplayList();
    group.add(pl);

    // Test
    setInterval(() => {
       console.time('body.reset');
       // this.pl.body.enable = false;
       // this.pl.body.enable = true;
       pl.body.reset(30, 30);
       console.timeEnd('body.reset');
    }, 1000);
}

Additional Information

@x-wk x-wk changed the title Reset a point light with a body takes a lot of time Reset a point light that has a body takes a lot of time Dec 3, 2021
@samme
Copy link
Contributor

samme commented Dec 3, 2021

Long story, but the ultimate problem is that StaticBody#reset() calls PointLight#getTopLeft(), which spoils the StaticBody#position values.

I think the GetBounds component needs to be removed from PointLight, since the methods will fail.

You can probably work around this by resetting the body manually — remove from static tree, modify position, insert in static tree. But you will have to figure out the offset between the body position (top-left) and light position (center).

@x-wk
Copy link
Author

x-wk commented Dec 4, 2021

Yes, I also found that the old body has not been removed from the static tree. I temporarily replaced it with other methods, thank you for your suggestion @samme

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants