Example usage for com.badlogic.gdx.graphics.g2d BitmapFont getColor

List of usage examples for com.badlogic.gdx.graphics.g2d BitmapFont getColor

Introduction

In this page you can find the example usage for com.badlogic.gdx.graphics.g2d BitmapFont getColor.

Prototype

public Color getColor() 

Source Link

Document

Returns the color of this font.

Usage

From source file:com.game.libgdx.roguelikeengine.PopupInfoText.java

License:Open Source License

public void drawScreen(SpriteBatch batch, BitmapFont font, String text, float fadein, int linedist, Color color,
        boolean resize) {
    float scaleX = font.getScaleX();
    float scaleY = font.getScaleY();

    update_x((int) (Gdx.graphics.getWidth() * 0.5f - this.width * 0.5f));
    update_y((int) (Gdx.graphics.getHeight() * 0.5f - this.height * 0.5f));

    mouseOverElement = "";
    if (!lastMessage.equals(text) || resize) {
        this.clearRenderWords();

        lineCount = 0;/*w ww .ja  v  a2 s. c o  m*/

        int linepos = 0;
        int currentWidth = textoffsetx;
        int nextWidth = 0;
        int maxWidth = (int) (width - textoffsetx);

        String[] words = null;
        for (String line : text.split("\n")) {
            lineCount = lineCount + 1;

            currentWidth = textoffsetx;

            words = line.split(" ");
            for (String word : words) {
                if (word.contains("\t")) {
                    word = word.replace("\t", "    ");
                }

                Color wordColor = color;
                if (word.length() > 7) {
                    String hex = word.substring(0, 7);

                    if (Pattern.matches(colorPattern, hex)) {
                        wordColor = this.hex2Rgb(hex);
                        word = word.replace(hex, "");
                    }
                }

                nextWidth = (int) (currentWidth + font.getBounds(word + " ").width);
                if (nextWidth > maxWidth) {
                    currentWidth = textoffsetx;
                    nextWidth = (int) (currentWidth + font.getBounds(word + " ").width);
                    linepos = linepos + 1;
                    lineCount = lineCount + 1;
                }

                int wordx = currentWidth;
                int wordy = height - ((textoffsety) + (linepos * linedist));

                this.addWordToRender(word,
                        new WordRectangle(wordx, wordy, font.getBounds(word + " ").width, font.getLineHeight())
                                .withColor(wordColor));

                currentWidth = nextWidth;
            }

            linepos++;
            currentWidth = x + textoffsetx;
        }
    }

    this.background.draw(batch, x, y, width, height);

    while (((lineCount * font.getLineHeight() + lineCount * linedist) * font.getScaleY()) > height
            - textoffsety) {
        font.setScale(font.getScaleY() - 0.1f);
    }

    if (font.getScaleY() != scaleY) {
        drawScreen(batch, font, text, fadein, linedist, color, true);
        font.setScale(scaleX, scaleY);
        return;
    }

    boolean anyClickable = false;
    Set<Entry<String, LinkedList<WordRectangle>>> keys = renderWords.entrySet();
    for (Entry<String, LinkedList<WordRectangle>> entry : keys) {
        for (WordRectangle rect : entry.getValue()) {
            font.setColor(rect.color.r, rect.color.g, rect.color.b, fadein);

            if (wordClickListeners.containsKey(entry.getKey())) {
                if (mouseOverWord(rect, font)) {
                    font.setColor(Color.BLUE.r, Color.BLUE.g, Color.BLUE.b, fadein);
                    mouseOverElement = entry.getKey();
                } else {
                    font.setColor(Color.CYAN);
                    font.setColor(Color.CYAN.r, Color.CYAN.g, Color.CYAN.b, fadein);
                }

                anyClickable = true;
            }

            font.draw(batch, entry.getKey().replace("_", " "), rect.x + x, rect.y + y);
        }
    }

    if (!anyClickable) {
        Color c = font.getColor();
        font.setColor(instructionsColor.r, instructionsColor.g, instructionsColor.b, fadein);
        font.draw(batch, instructions, x + (width * 0.5f) - (font.getBounds(instructions).width * 0.5f),
                y + font.getBounds(instructions).height + Gdx.graphics.getHeight() * 0.05f);
        font.setColor(c);
    }

    lastMessage = text;
    font.setScale(scaleX, scaleY);
}

From source file:com.turbogerm.helljump.game.items.ItemBase.java

License:Open Source License

public final void renderText(SpriteBatch batch, float visibleAreaPosition, BitmapFont itemFont) {
    if (mItemState == TEXT_STATE) {
        if (mIsPickedUpTextBoundsDirty) {
            TextBounds textBounds = itemFont.getBounds(mPickedUpText);
            mPickedUpTextBounds.set(textBounds.width, textBounds.height);
            mIsPickedUpTextBoundsDirty = false;
        }//from  w  w w  .  j a v  a  2  s  .  c  o  m
        float alpha = mTextCountdown / TEXT_COUNTDOWN_DURATION;
        Color c = itemFont.getColor();
        itemFont.setColor(c.r, c.g, c.b, alpha);
        float textX = (mPosition.x + mSize.x / 2.0f) * GameAreaUtils.METER_TO_PIXEL
                - mPickedUpTextBounds.x / 2.0f;
        textX = MathUtils.clamp(textX, 0.0f, HellJump.VIEWPORT_WIDTH - mPickedUpTextBounds.x);
        float textY = (mPosition.y + mSize.y / 2.0f - visibleAreaPosition) * GameAreaUtils.METER_TO_PIXEL
                + mPickedUpTextBounds.y / 2.0f;
        itemFont.draw(batch, mPickedUpText, textX, textY);
    }
}

From source file:scenes.FontFade.java

public FontFade(BitmapFont font) {
    this.font = font;
    this.alpha = font.getColor().a;
    this.step = -0.01f;
}