use of com.b3dgs.lionengine.game.State in project lionengine by b3dgs.
the class StateHandler method update.
/*
* Updatable
*/
@Override
public void update(double extrp) {
if (current != null) {
for (final InputDevice input : inputs) {
updateInput(StateInputDirectionalUpdater.class, InputDeviceDirectional.class, input);
updateInput(StateInputPointerUpdater.class, InputDevicePointer.class, input);
}
current.update(extrp);
final State old = current;
for (final InputDevice input : inputs) {
current = checkNext(InputDeviceDirectional.class, input);
if (!old.equals(current)) {
break;
}
current = checkNext(InputDevicePointer.class, input);
if (!old.equals(current)) {
break;
}
}
if (!old.equals(current)) {
old.exit();
}
}
}
use of com.b3dgs.lionengine.game.State in project lionengine by b3dgs.
the class StateHandlerTest method testTransition.
/**
* Test the state transitions.
*/
@Test
public void testTransition() {
final State idle = new StateIdle();
factory.addState(idle);
factory.addState(new StateWalk());
handler.addInput(new InputDirectionalMock());
handler.addInput(new InputPointerMock());
handler.changeState(StateType.IDLE);
Assert.assertTrue(handler.isState(StateType.IDLE));
handler.update(1.0);
Assert.assertTrue(handler.isState(StateType.WALK));
handler.update(1.0);
Assert.assertTrue(handler.isState(StateType.IDLE));
idle.clearTransitions();
handler.update(1.0);
Assert.assertTrue(handler.isState(StateType.IDLE));
}
use of com.b3dgs.lionengine.game.State in project lionengine by b3dgs.
the class StateAnimationUtil method loadStates.
/**
* Load all existing animations defined in the xml file.
*
* @param states The states values.
* @param factory The factory reference.
* @param provider The featurable reference.
* @param setup The setup reference.
*/
public static void loadStates(StateAnimationBased[] states, StateFactory factory, FeatureProvider provider, Setup setup) {
final AnimationConfig configAnimations = AnimationConfig.imports(setup);
for (final StateAnimationBased type : states) {
try {
final Animation animation = configAnimations.getAnimation(type.getAnimationName());
final State state = UtilReflection.create(type.getStateClass(), UtilReflection.getParamTypes(provider, animation), provider, animation);
factory.addState(state);
} catch (final NoSuchMethodException exception) {
throw new LionEngineException(exception);
}
}
}
Aggregations