Closed taluks closed 3 years ago
Script has an act
method which is called by the built in ScriptSystem
that you can use to check if the body is null or not. Don't need to call process anywhere into script.
Btw, for this kind of question we have a Discord server where we can discuss, feel free to join :)
Also, Scripts are automatically injected by artemis, so no need to pass world (engine) reference.. Use this as example:
public class PhysicsTestScript extends BasicScript implements PhysicsContact {
//No needs to init these fields because scripts are injected using artemis
protected ComponentMapper<PhysicsBodyComponent> physicMapper;
protected com.artemis.World engine;
//This has to be initialized!
private PhysicsBodyComponent physicsBodyComponent;
@Override
public void init (int item) {
super.init(item);
physicsBodyComponent = physicMapper.get(item);
}
@Override
public void act (float delta) {
//body can be used here, because act method is called after PhysicsSystem,
//so all bodies should already be created
Body body = physicsBodyComponent.body;
}
@Override
public void beginContact (int contactEntity, Fixture contactFixture, Fixture ownFixture, Contact contact) {
}
@Override
public void endContact (int contactEntity, Fixture contactFixture, Fixture ownFixture, Contact contact) {
}
@Override
public void preSolve (int contactEntity, Fixture contactFixture, Fixture ownFixture, Contact contact) {
}
@Override
public void postSolve (int contactEntity, Fixture contactFixture, Fixture ownFixture, Contact contact) {
}
@Override
public void dispose () {
}
}
Physics body is null.
in 50% we can see error java.lang.NullPointerException
♿♿♿ My solution: while(pbComponent.body==null) engine.process();