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

com.uwsoft.editor.renderer.systems.SpriteAnimationSystem Maven / Gradle / Ivy

Go to download

overlap2d-runtime-libgdx provides functionality to load, manipulate and render scenes generated by Overlap2D.

The newest version!
package com.uwsoft.editor.renderer.systems;

import com.badlogic.ashley.core.ComponentMapper;
import com.badlogic.ashley.core.Entity;
import com.badlogic.ashley.core.Family;
import com.badlogic.ashley.systems.IteratingSystem;
import com.uwsoft.editor.renderer.components.TextureRegionComponent;
import com.uwsoft.editor.renderer.components.sprite.SpriteAnimationComponent;
import com.uwsoft.editor.renderer.components.sprite.SpriteAnimationStateComponent;

public class SpriteAnimationSystem extends IteratingSystem {
	private ComponentMapper tm;
	private ComponentMapper sm;
    private ComponentMapper sa;

	public SpriteAnimationSystem() {
		super(Family.all(SpriteAnimationStateComponent.class).get());

		tm = ComponentMapper.getFor(TextureRegionComponent.class);
		sm = ComponentMapper.getFor(SpriteAnimationStateComponent.class);
        sa = ComponentMapper.getFor(SpriteAnimationComponent.class);
	}

	@Override
	public void processEntity(Entity entity, float deltaTime) {
		TextureRegionComponent tex = tm.get(entity);
		SpriteAnimationStateComponent state = sm.get(entity);
        state.currentAnimation.setFrameDuration(1f/sa.get(entity).fps);
		tex.region = state.currentAnimation.getKeyFrame(state.time);
		state.time += deltaTime;
	}

}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy