use of com.gemserk.commons.gdx.games.Spatial in project commons-gdx by gemserk.
the class EntityTemplateTest method testModifyPositionByHand.
@Test
public void testModifyPositionByHand() {
// default parameters through a custom template, could be created when the level starts with custom level information
EntityTemplate customShipTemplate = new ShipEntityTemplate() {
{
parameters.put("health", new Container(250f, 250f));
}
};
EntityFactory entityFactory = new EntityFactoryImpl(new World());
Entity entity = entityFactory.instantiate(customShipTemplate);
SpatialComponent spatialComponent = entity.getComponent(SpatialComponent.class);
Spatial spatial = spatialComponent.getSpatial();
spatial.setPosition(100f, 100f);
}
use of com.gemserk.commons.gdx.games.Spatial 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);
}
}
use of com.gemserk.commons.gdx.games.Spatial 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());
}
Aggregations