All Downloads are FREE. Search and download functionalities are using the official Maven repository.

games.rednblack.editor.renderer.systems.SpriteAnimationSystem Maven / Gradle / Ivy

The newest version!
package games.rednblack.editor.renderer.systems;

import com.artemis.ComponentMapper;
import com.artemis.annotations.All;
import com.artemis.systems.IteratingSystem;
import games.rednblack.editor.renderer.components.TextureRegionComponent;
import games.rednblack.editor.renderer.components.sprite.SpriteAnimationComponent;
import games.rednblack.editor.renderer.components.sprite.SpriteAnimationStateComponent;

@All(SpriteAnimationComponent.class)
public class SpriteAnimationSystem extends IteratingSystem {
    protected ComponentMapper tm;
    protected ComponentMapper sm;
    protected ComponentMapper sa;

    @Override
    protected void process(int entityId) {
        TextureRegionComponent tex = tm.get(entityId);
        SpriteAnimationStateComponent state = sm.get(entityId);
        state.currentAnimation.setFrameDuration(1f / sa.get(entityId).fps);
        tex.region = state.currentAnimation.getKeyFrame(state.time);

        if (!state.paused) {
            state.time += world.delta;
        }
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy