The java version:
public EntityHolder object;
public Body body; << The field what I need to set after the object was created.
@Override
protected boolean act(Fixture f1, int value) {
count +=value;
try {
if (((Entity) f1.getBody().getUserData()).getComponent(IdentifierComponent.class).type == IdentifierComponent.Type.Player.value)
{
if(count ==1) {
((GameScreen) Gdx.app.getApplicationListener()).addScore(score);
object.exists = false;
body.setUserData(StaticVariables.DELETE);
}
return false;
}
} catch (Exception e) {
Gdx.app.log(this.getClass().getSimpleName(),e.toString());
}
The object is being obtained from a pool, so there is no way to set the body variable while initializing. I tried to set it to a “blank” body, but since the init method is protected that’s not an option.
I see the point, but (I’m sure to be wrong) it might kill pooling if there is no option to create a field like this.
(android code, I know theres a way to not to loose performance with getters and setters, but it was dismantling the apis I use so I opted it out for now)
Libgdx uses a native implementation of Box2d, all the code is behind a Wrapper.
public class WheeledBody implements Component,Pool.Poolable {
public Body body;
public Body foot;
public RevoluteJoint motor;
public boolean exists = false;
public boolean wallblocked = true;
public float Speed;
public boolean isMoving=true;
public boolean Forward=true;
public Sensor groundSensor;
public Sensor headSensor;
public Sensor leftSensor;
public Sensor rightSensor;
public float TORQUE;
@Override
public void reset() {
body.setUserData(StaticVariables.DELETE);
foot.setUserData(StaticVariables.DELETE);
motor.setUserData(StaticVariables.DELETE);
exists =false;
groundSensor = null;
leftSensor = null;
rightSensor = null;
headSensor = null;
wallblocked = true;
isMoving = true;
Forward = true;
}
}
Also using ashly, and this is how they meant to use it.
(How to use Ashley · libgdx/ashley Wiki · GitHub)
So, I am having something whitch would be (Just read about it) data class, but its also having a reset method to set it to the defaults.