You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
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
The text was updated successfully, but these errors were encountered:
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
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).
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
Version
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
Additional Information
The text was updated successfully, but these errors were encountered: