Fix effects being applied multiple times on objects when creating and destroying a lot of them (#3149)

* Effects from destroyed objects could be cleaned incorrectly and applied to new objects, creating glitches on newly created objects.
This commit is contained in:
Clément Pasteau
2021-10-08 17:14:23 +02:00
committed by GitHub
parent 2c24359fba
commit bc23d6a084
2 changed files with 35 additions and 1 deletions

View File

@@ -141,6 +141,17 @@ namespace gdjs {
return true;
}
/**
* Remove all effects from a PixiJS DisplayObject.
* @param rendererObject The renderer object.
*/
clearEffects(rendererObject: PIXI.DisplayObject): boolean {
if (rendererObject) {
rendererObject.filters = [];
}
return true;
}
/**
* Update the parameter of an effect (with a number).
* @param rendererEffects The collection of PixiJS filters.

View File

@@ -181,6 +181,8 @@ namespace gdjs {
this.aabb.max[1] = 0;
this._variables = new gdjs.VariablesContainer(objectData.variables);
this.clearForces();
// Reinitialize behaviors.
this._behaviorsTable.clear();
let i = 0;
for (const len = objectData.behaviors.length; i < len; ++i) {
@@ -196,7 +198,16 @@ namespace gdjs {
}
this._behaviors.length = i;
// Make sure to delete already existing behaviors which are not used anymore.
// Reinitialize effects.
for (let i = 0; i < objectData.effects.length; ++i) {
this._runtimeScene
.getGame()
.getEffectsManager()
.initializeEffect(objectData.effects[i], this._rendererEffects, this);
this.updateAllEffectParameters(objectData.effects[i]);
}
// Make sure to delete existing timers.
this._timers.clear();
}
@@ -291,6 +302,7 @@ namespace gdjs {
for (let j = 0, lenj = this._behaviors.length; j < lenj; ++j) {
this._behaviors[j].onDestroy();
}
this.clearEffects();
}
//Rendering:
@@ -793,6 +805,17 @@ namespace gdjs {
);
}
/**
* Remove all effects.
*/
clearEffects(): boolean {
this._rendererEffects = {};
return this._runtimeScene
.getGame()
.getEffectsManager()
.clearEffects(this.getRendererObject());
}
/**
* Change an effect parameter value (for parameters that are numbers).
* @param name The name of the effect to update.