-1
\$\begingroup\$

I'm trying to create a Minecraft like quotes on the menu screen of my game.

I'm using BitmapFont to draw the text on screen but I don't know how to make that scale up scale down effect.

This is what I tried to do.

public class MenuQuotes extends Actor {
    private BitmapFont font16;
    private String     str;

    public MenuQuotes() {
        FreeTypeFontGenerator generator = new FreeTypeFontGenerator(Gdx.files.internal("fonts/minecraft.ttf"));
        FreeTypeFontGenerator.FreeTypeFontParameter parameter = new FreeTypeFontGenerator.FreeTypeFontParameter();

        parameter.size = 16;
        parameter.color = Color.WHITE;
        parameter.shadowColor = Color.BLACK;
        parameter.shadowOffsetX = 1;
        parameter.shadowOffsetY = 1;

        font16 = generator.generateFont(parameter);
        generator.dispose();
    }

    @Override
    public void draw(Batch batch, float alpha) {
        super.draw(batch, alpha);

        ScaleToAction scaleAction = new ScaleToAction();
        scaleAction.setScale(10, 10);
        scaleAction.setDuration(10);

        GlyphLayout glyphLayout = new GlyphLayout();
        str = "Chickens are the closest relative\nto Tyrannosaurus";
        glyphLayout.setText(font16, str);
        float w = glyphLayout.width;

        font16.draw(batch, str, (Chicken.V_WIDTH / 2) / 2 - w / 2, (Chicken.V_HEIGHT / 2) / 2 + 10);
        this.addAction(scaleAction);

    }

    @Override
    public void act(float delta) {
        super.act(delta);
    }
}
\$\endgroup\$
  • \$\begingroup\$ What scale-up-scale-down effect? Could you add an animated gif or a link to the relevant part of a video? \$\endgroup\$ – Vaillancourt Jun 21 '17 at 16:01
0
\$\begingroup\$

The Actor class provides attributes to apply transformation to entities like Textures or BitmapFonts. The ScaleToAction you added only modifies the attributes derived by the Actor class. To apply the Action to your BitmapFont you have to apply the scale of the Actor to your BitmapFont. This topic shows how to do that.

| improve this answer | |
\$\endgroup\$
  • \$\begingroup\$ I'll add that Label class can't be resized by actions. You can achieve a scale up scale down action by making a table containing your label and table.setTransformation(true) \$\endgroup\$ – Sebastien Servouze Feb 7 '17 at 11:25
0
\$\begingroup\$

If you don't mind the pixelation due to scaling you can use font.getData().setScale(float value) with a interpolation value. I generally use Tween to set this kind of animations to scale up or down. Or you can use a counter to set scaling animation.

| improve this answer | |
\$\endgroup\$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.