Search in sources :

Example 6 with SpatialComponent

use of com.gemserk.commons.artemis.components.SpatialComponent in project commons-gdx by gemserk.

the class SpriteUpdateSystem method processEntities.

@Override
protected void processEntities() {
    RandomAccessMap<Entity, EntityComponents> allTheEntityComponents = factory.entityComponents;
    int entitiesSize = allTheEntityComponents.size();
    for (int entityIndex = 0; entityIndex < entitiesSize; entityIndex++) {
        EntityComponents components = allTheEntityComponents.get(entityIndex);
        SpatialComponent spatialComponent = components.spatialComponent;
        SpriteComponent spriteComponent = components.spriteComponent;
        PreviousStateSpatialComponent previousStateSpatialComponent = components.previousStateSpatialComponent;
        Spatial spatial = spatialComponent.getSpatial();
        float x = spatial.getX();
        float y = spatial.getY();
        float angle = spatial.getAngle();
        if (previousStateSpatialComponent != null) {
            float interpolationAlpha = timeStepProvider.getAlpha();
            Spatial previousSpatial = previousStateSpatialComponent.getSpatial();
            x = FloatInterpolator.interpolate(previousSpatial.getX(), spatial.getX(), interpolationAlpha);
            y = FloatInterpolator.interpolate(previousSpatial.getY(), spatial.getY(), interpolationAlpha);
            float angleDiff = (float) AngleUtils.minimumDifference(previousSpatial.getAngle(), spatial.getAngle());
            angle = FloatInterpolator.interpolate(spatial.getAngle() - angleDiff, spatial.getAngle(), interpolationAlpha);
        }
        spriteComponent.update(x, y, spatial.getWidth(), spatial.getHeight(), angle);
    }
}
Also used : Entity(com.artemis.Entity) SpriteComponent(com.gemserk.commons.artemis.components.SpriteComponent) Spatial(com.gemserk.commons.gdx.games.Spatial) PreviousStateSpatialComponent(com.gemserk.commons.artemis.components.PreviousStateSpatialComponent) SpatialComponent(com.gemserk.commons.artemis.components.SpatialComponent) PreviousStateSpatialComponent(com.gemserk.commons.artemis.components.PreviousStateSpatialComponent)

Example 7 with SpatialComponent

use of com.gemserk.commons.artemis.components.SpatialComponent in project commons-gdx by gemserk.

the class ParticleEmitterSystem method process.

@Override
protected void process(Entity e) {
    SpatialComponent spatialComponent = Components.getSpatialComponent(e);
    Spatial spatial = spatialComponent.getSpatial();
    ParticleEmitterComponent particleEmitterComponent = Components.getParticleEmitterComponent(e);
    particleEmitterComponent.particleEmitter.setPosition(spatial.getX(), spatial.getY());
    particleEmitterComponent.particleEmitter.update(GlobalTime.getDelta());
}
Also used : Spatial(com.gemserk.commons.gdx.games.Spatial) SpatialComponent(com.gemserk.commons.artemis.components.SpatialComponent) ParticleEmitterComponent(com.gemserk.commons.artemis.components.ParticleEmitterComponent)

Aggregations

SpatialComponent (com.gemserk.commons.artemis.components.SpatialComponent)7 Spatial (com.gemserk.commons.gdx.games.Spatial)6 Entity (com.artemis.Entity)5 World (com.artemis.World)3 EntityFactory (com.gemserk.commons.artemis.templates.EntityFactory)3 EntityFactoryImpl (com.gemserk.commons.artemis.templates.EntityFactoryImpl)3 EntityTemplate (com.gemserk.commons.artemis.templates.EntityTemplate)3 Test (org.junit.Test)3 PreviousStateSpatialComponent (com.gemserk.commons.artemis.components.PreviousStateSpatialComponent)2 Container (com.gemserk.componentsengine.utils.Container)2 ParticleEmitterComponent (com.gemserk.commons.artemis.components.ParticleEmitterComponent)1 ScriptComponent (com.gemserk.commons.artemis.components.ScriptComponent)1 SpriteComponent (com.gemserk.commons.artemis.components.SpriteComponent)1 TextComponent (com.gemserk.commons.artemis.components.TextComponent)1 Script (com.gemserk.commons.artemis.scripts.Script)1 ScriptJavaImpl (com.gemserk.commons.artemis.scripts.ScriptJavaImpl)1 ParametersWrapper (com.gemserk.componentsengine.utils.ParametersWrapper)1