Search in sources :

Example 41 with Animation

use of com.b3dgs.lionengine.Animation in project lionengine by b3dgs.

the class StateHandler method create.

/**
 * Create state from its type.
 *
 * @param state The state to create (must not be <code>null</code>).
 * @return The created state.
 * @throws LionEngineException If unable to create state.
 */
@SuppressWarnings("unchecked")
private State create(Class<? extends State> state) {
    Check.notNull(state);
    try {
        if (setup.hasNode(AnimationConfig.NODE_ANIMATIONS)) {
            final AnimationConfig configAnimations = AnimationConfig.imports(setup);
            final String name = converter.apply(state);
            final Animation animation = configAnimations.getAnimation(name);
            final Class<? extends Feature> feature;
            feature = (Class<? extends Feature>) UtilReflection.getCompatibleConstructor(state, FeatureProvider.class, Animation.class).getParameters()[PARAM_FEATURE_INDEX].getType();
            return UtilReflection.create(state, UtilReflection.getParamTypes(feature, animation), getFeature(feature), animation);
        }
        return UtilReflection.createReduce(state);
    } catch (final LionEngineException exception) {
        throw new LionEngineException(exception, setup.getMedia());
    } catch (final NoSuchMethodException exception) {
        throw new LionEngineException(exception);
    }
}
Also used : LionEngineException(com.b3dgs.lionengine.LionEngineException) Animation(com.b3dgs.lionengine.Animation) FeatureProvider(com.b3dgs.lionengine.game.FeatureProvider) AnimationConfig(com.b3dgs.lionengine.game.AnimationConfig)

Aggregations

Animation (com.b3dgs.lionengine.Animation)41 Test (org.junit.jupiter.api.Test)19 Test (org.junit.Test)13 Animator (com.b3dgs.lionengine.Animator)9 SpriteAnimated (com.b3dgs.lionengine.graphic.SpriteAnimated)6 HashMap (java.util.HashMap)5 Xml (com.b3dgs.lionengine.Xml)4 AnimatorModel (com.b3dgs.lionengine.AnimatorModel)3 Media (com.b3dgs.lionengine.Media)3 AnimatableModel (com.b3dgs.lionengine.game.feature.AnimatableModel)3 TransformableModel (com.b3dgs.lionengine.game.feature.TransformableModel)3 Collision (com.b3dgs.lionengine.game.feature.collidable.Collision)3 Collection (java.util.Collection)3 AtomicReference (java.util.concurrent.atomic.AtomicReference)3 AnimState (com.b3dgs.lionengine.AnimState)2 AnimatorListener (com.b3dgs.lionengine.AnimatorListener)2 LionEngineException (com.b3dgs.lionengine.LionEngineException)2 AnimationConfig (com.b3dgs.lionengine.game.AnimationConfig)2 Configurer (com.b3dgs.lionengine.game.Configurer)2 Animatable (com.b3dgs.lionengine.game.feature.Animatable)2