Search in sources :

Example 1 with PreviousStateSpatialComponent

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

the class PreviousStateSpatialSystem method processEntities.

@Override
protected void processEntities() {
    RandomAccessMap<Entity, EntityComponents> allTheEntityComponents = factory.entityComponents;
    int entitiesSize = allTheEntityComponents.size();
    for (int e = 0; e < entitiesSize; e++) {
        EntityComponents entityComponents = allTheEntityComponents.get(e);
        SpatialComponent spatialComponent = entityComponents.spatialComponent;
        PreviousStateSpatialComponent previousStateSpatialComponent = entityComponents.previousStateSpatialComponent;
        Spatial spatial = spatialComponent.getSpatial();
        Spatial previousSpatial = previousStateSpatialComponent.getSpatial();
        previousSpatial.set(spatial);
    }
}
Also used : Entity(com.artemis.Entity) 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 2 with PreviousStateSpatialComponent

use of com.gemserk.commons.artemis.components.PreviousStateSpatialComponent 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)

Aggregations

Entity (com.artemis.Entity)2 PreviousStateSpatialComponent (com.gemserk.commons.artemis.components.PreviousStateSpatialComponent)2 SpatialComponent (com.gemserk.commons.artemis.components.SpatialComponent)2 Spatial (com.gemserk.commons.gdx.games.Spatial)2 SpriteComponent (com.gemserk.commons.artemis.components.SpriteComponent)1