use of com.gemserk.commons.artemis.components.SpriteComponent in project commons-gdx by gemserk.
the class RenderLayerSpriteBatchImpl method render.
@Override
public void render() {
camera.getFrustum(frustum);
if (optimizationParameters.updateCamera)
camera.apply(spriteBatch);
RandomAccessMap<Entity, EntityComponents> entityComponents = factory.entityComponents;
if (blending && !spriteBatch.isBlendingEnabled())
spriteBatch.enableBlending();
else if (!blending && spriteBatch.isBlendingEnabled())
spriteBatch.disableBlending();
if (optimizationParameters.beginBatch)
spriteBatch.begin();
for (int i = 0; i < orderedByLayerRenderables.size(); i++) {
Renderable renderable = orderedByLayerRenderables.get(i);
if (!renderable.isVisible())
continue;
EntityComponents components = entityComponents.get(renderable.getEntity());
FrustumCullingComponent frustumCullingComponent = components.frustumCullingComponent;
if (frustumCullingComponent != null) {
Spatial spatial = components.spatialComponent.getSpatial();
entityBounds.set(frustumCullingComponent.bounds);
entityBounds.setX(entityBounds.getX() + spatial.getX());
entityBounds.setY(entityBounds.getY() + spatial.getY());
if (!frustum.overlaps(entityBounds))
continue;
}
SpriteComponent spriteComponent = components.spriteComponent;
if (spriteComponent != null) {
Sprite sprite = spriteComponent.getSprite();
sprite.setColor(spriteComponent.getColor());
sprite.draw(spriteBatch);
}
// don't like it will be asking for components all the time.
TextComponent textComponent = components.textComponent;
if (textComponent != null) {
BitmapFont font = textComponent.font;
if (font.getScaleX() != textComponent.scale) {
font.setScale(textComponent.scale);
}
font.setColor(textComponent.color);
//
SpriteBatchUtils.drawMultilineText(//
spriteBatch, //
font, textComponent.text, textComponent.x, textComponent.y, textComponent.cx, textComponent.cy);
}
ParticleEmitterComponent particleEmitterComponent = components.particleEmitterComponent;
if (particleEmitterComponent != null) {
particleEmitterComponent.particleEmitter.draw(spriteBatch);
}
}
if (optimizationParameters.endBatch)
spriteBatch.end();
}
use of com.gemserk.commons.artemis.components.SpriteComponent 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);
}
}
Aggregations