Search in sources :

Example 1 with Renderable

use of com.gemserk.commons.artemis.render.Renderable in project commons-gdx by gemserk.

the class RenderableSystem method enabled.

@Override
protected void enabled(Entity e) {
    RenderableComponent renderableComponent = RenderableComponent.get(e);
    OwnerComponent ownerComponent = OwnerComponent.get(e);
    Renderable renderable = renderableComponent.renderable;
    // this could be set on construction time
    renderable.setEntity(e);
    renderable.setId(e.getId());
    // if it has owner it uses the id of the owner... that was part of the original comparator
    if (ownerComponent != null && ownerComponent.getOwner() != null)
        renderable.setId(ownerComponent.getOwner().getId());
    // order the entity in the Layer, probably the same inside the layer
    for (int i = 0; i < renderLayers.size(); i++) {
        RenderLayer renderLayer = renderLayers.get(i);
        if (renderLayer.belongs(renderable)) {
            renderLayer.add(renderable);
            return;
        }
    }
}
Also used : Renderable(com.gemserk.commons.artemis.render.Renderable) OwnerComponent(com.gemserk.commons.artemis.components.OwnerComponent) RenderableComponent(com.gemserk.commons.artemis.components.RenderableComponent)

Example 2 with Renderable

use of com.gemserk.commons.artemis.render.Renderable 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();
}
Also used : TextComponent(com.gemserk.commons.artemis.components.TextComponent) Entity(com.artemis.Entity) Renderable(com.gemserk.commons.artemis.render.Renderable) Sprite(com.badlogic.gdx.graphics.g2d.Sprite) Spatial(com.gemserk.commons.gdx.games.Spatial) SpriteComponent(com.gemserk.commons.artemis.components.SpriteComponent) FrustumCullingComponent(com.gemserk.commons.artemis.components.FrustumCullingComponent) BitmapFont(com.badlogic.gdx.graphics.g2d.BitmapFont) ParticleEmitterComponent(com.gemserk.commons.artemis.components.ParticleEmitterComponent)

Example 3 with Renderable

use of com.gemserk.commons.artemis.render.Renderable in project commons-gdx by gemserk.

the class RenderableSystem method disabled.

@Override
protected void disabled(Entity e) {
    RenderableComponent renderableComponent = RenderableComponent.get(e);
    Renderable renderable = renderableComponent.renderable;
    // remove the order
    for (int i = 0; i < renderLayers.size(); i++) {
        RenderLayer renderLayer = renderLayers.get(i);
        if (renderLayer.belongs(renderable)) {
            renderLayer.remove(renderable);
            return;
        }
    }
}
Also used : Renderable(com.gemserk.commons.artemis.render.Renderable) RenderableComponent(com.gemserk.commons.artemis.components.RenderableComponent)

Aggregations

Renderable (com.gemserk.commons.artemis.render.Renderable)3 RenderableComponent (com.gemserk.commons.artemis.components.RenderableComponent)2 Entity (com.artemis.Entity)1 BitmapFont (com.badlogic.gdx.graphics.g2d.BitmapFont)1 Sprite (com.badlogic.gdx.graphics.g2d.Sprite)1 FrustumCullingComponent (com.gemserk.commons.artemis.components.FrustumCullingComponent)1 OwnerComponent (com.gemserk.commons.artemis.components.OwnerComponent)1 ParticleEmitterComponent (com.gemserk.commons.artemis.components.ParticleEmitterComponent)1 SpriteComponent (com.gemserk.commons.artemis.components.SpriteComponent)1 TextComponent (com.gemserk.commons.artemis.components.TextComponent)1 Spatial (com.gemserk.commons.gdx.games.Spatial)1