Search in sources :

Example 1 with TransformDrawable

use of com.badlogic.gdx.scenes.scene2d.utils.TransformDrawable in project libgdx by libgdx.

the class Image method draw.

public void draw(Batch batch, float parentAlpha) {
    validate();
    Color color = getColor();
    batch.setColor(color.r, color.g, color.b, color.a * parentAlpha);
    float x = getX();
    float y = getY();
    float scaleX = getScaleX();
    float scaleY = getScaleY();
    if (drawable instanceof TransformDrawable) {
        float rotation = getRotation();
        if (scaleX != 1 || scaleY != 1 || rotation != 0) {
            ((TransformDrawable) drawable).draw(batch, x + imageX, y + imageY, getOriginX() - imageX, getOriginY() - imageY, imageWidth, imageHeight, scaleX, scaleY, rotation);
            return;
        }
    }
    if (drawable != null)
        drawable.draw(batch, x + imageX, y + imageY, imageWidth * scaleX, imageHeight * scaleY);
}
Also used : Color(com.badlogic.gdx.graphics.Color) TransformDrawable(com.badlogic.gdx.scenes.scene2d.utils.TransformDrawable)

Example 2 with TransformDrawable

use of com.badlogic.gdx.scenes.scene2d.utils.TransformDrawable in project bladecoder-adventure-engine by bladecoder.

the class DefaultSceneScreen method drawHotspots.

private void drawHotspots(SpriteBatch batch) {
    final World world = World.getInstance();
    for (BaseActor a : world.getCurrentScene().getActors().values()) {
        if (!(a instanceof InteractiveActor) || !a.isVisible() || a == world.getCurrentScene().getPlayer())
            continue;
        InteractiveActor ia = (InteractiveActor) a;
        if (!ia.canInteract())
            continue;
        Polygon p = a.getBBox();
        if (p == null) {
            EngineLogger.error("ERROR DRAWING HOTSPOT FOR: " + a.getId());
        }
        Rectangle r = a.getBBox().getBoundingRectangle();
        unprojectTmp.set(r.getX() + r.getWidth() / 2, r.getY() + r.getHeight() / 2, 0);
        world.getSceneCamera().scene2screen(viewport, unprojectTmp);
        if (!showDesc || ia.getDesc() == null) {
            float size = DPIUtils.ICON_SIZE * DPIUtils.getSizeMultiplier();
            if (ia.getVerb("leave") != null) {
                TransformDrawable drawable = (TransformDrawable) getUI().getSkin().getDrawable("leave");
                drawable.draw(batch, unprojectTmp.x - size / 2, unprojectTmp.y - size / 2, size / 2, size / 2, size, size, 1.0f, 1.0f, calcLeaveArrowRotation(ia));
            } else {
                Drawable drawable = getUI().getSkin().getDrawable("hotspot");
                if (drawable != null)
                    drawable.draw(batch, unprojectTmp.x - size / 2, unprojectTmp.y - size / 2, size, size);
            }
        } else {
            BitmapFont font = getUI().getSkin().getFont("desc");
            String desc = ia.getDesc();
            if (desc.charAt(0) == I18N.PREFIX)
                desc = I18N.getString(desc.substring(1));
            textLayout.setText(font, desc);
            float textX = unprojectTmp.x - textLayout.width / 2;
            float textY = unprojectTmp.y + textLayout.height;
            RectangleRenderer.draw(batch, textX - 8, textY - textLayout.height - 8, textLayout.width + 16, textLayout.height + 16, Color.BLACK);
            font.draw(batch, textLayout, textX, textY);
        }
    }
}
Also used : InteractiveActor(com.bladecoder.engine.model.InteractiveActor) TransformDrawable(com.badlogic.gdx.scenes.scene2d.utils.TransformDrawable) Rectangle(com.badlogic.gdx.math.Rectangle) Drawable(com.badlogic.gdx.scenes.scene2d.utils.Drawable) TransformDrawable(com.badlogic.gdx.scenes.scene2d.utils.TransformDrawable) BaseActor(com.bladecoder.engine.model.BaseActor) World(com.bladecoder.engine.model.World) Polygon(com.badlogic.gdx.math.Polygon) BitmapFont(com.badlogic.gdx.graphics.g2d.BitmapFont)

Aggregations

TransformDrawable (com.badlogic.gdx.scenes.scene2d.utils.TransformDrawable)2 Color (com.badlogic.gdx.graphics.Color)1 BitmapFont (com.badlogic.gdx.graphics.g2d.BitmapFont)1 Polygon (com.badlogic.gdx.math.Polygon)1 Rectangle (com.badlogic.gdx.math.Rectangle)1 Drawable (com.badlogic.gdx.scenes.scene2d.utils.Drawable)1 BaseActor (com.bladecoder.engine.model.BaseActor)1 InteractiveActor (com.bladecoder.engine.model.InteractiveActor)1 World (com.bladecoder.engine.model.World)1