How to avoid using Poolable Component?
Closed this issue · 2 comments
ronjunevaldoz commented
public class AnimationComponent implements Component {
IntMap<Animation> map ...
}
if AnimationComponent
is removed from the PooledEngine
, the animation map value is not automatically cleared.
Ex. The character animation will remain in the map, if you create another entity, let say a coin then add animation. The coin animation will be character animation.
Entity character = engine.createEntity();
AnimationComponent animation = engine.createComponent(AnimationComponent.class);
animation.map.put(0, CHARACTER_WALKING );
character.add(animation);
engine.add(character);
engine.removeEntity(character);
Entity coin = engine.createEntity();
AnimationComponent animation = engine.createComponent(AnimationComponent.class);
animation.map.put(0, COIN);
coin.add(animation);
engine.add(coin);
The solution. But I'm afraid because I always forgot to add Poolable to my newly created component, that's why I want to avoid using Poolable.
AnimationComponent implements Poolable {
@override
public void reset() {
map.clear();
}
}
dlux95 commented
Perhaps using an abstract class BaseComponent which implements Poolable and than let all your components extend BaseComponent? Or something similar.
dsaltares commented
As the wiki states, you should implement the Poolable
interface if your components need to be cleaned up when returned to the pool.
Example:
public class PositionComponent implements Component, Poolable {
public float x = 0.0f;
public float y = 0.0f;
@Override
public void reset() {
x = 0.0f;
y = 0.0f;
}
}