libgdx中BitmapFont字体的使用


1.Fnt字体

有字体

font/huawenxinwei_36_w.fnt

配合字体图片

"font/huawenxinwei_36_w1.png"

"font/huawenxinwei_36_w2.png"

"font/huawenxinwei_36_w3.png"

"font/huawenxinwei_36_w4.png"

使用方法如下:

package dy.android.cike.cocos.ui.test.move;

import com.badlogic.gdx.Gdx;
import com.badlogic.gdx.Input;
import com.badlogic.gdx.InputProcessor;
import com.badlogic.gdx.files.FileHandle;
import com.badlogic.gdx.graphics.Color;
import com.badlogic.gdx.graphics.GL20;
import com.badlogic.gdx.graphics.g2d.Batch;
import com.badlogic.gdx.graphics.g2d.BitmapFont;
import com.badlogic.gdx.graphics.g2d.TextureRegion;
import df.util.Util;
import dy.android.cike.cocos.base.UiBaseGroup;

/**
 * Created by andrew on 2015/1/7.
 */
public class TestMoveGroup extends UiBaseGroup implements InputProcessor {
    private static final String TAG = Util.toTAG(TestMoveGroup.class);
    BitmapFont bitFnt = null;

    public TestMoveGroup() {
        super("cocostudio/ui_end/ui_end.json");
        initFont();
    }



    private void initFont(){
        String[] images = new String[]{"font/huawenxinwei_36_w1.png",
                "font/huawenxinwei_36_w2.png",
                "font/huawenxinwei_36_w3.png",
                "font/huawenxinwei_36_w4.png"};
        FileHandle fntFile = Gdx.files.internal("font/huawenxinwei_36_w.fnt");
        BitmapFont.BitmapFontData data = new BitmapFont.BitmapFontData(fntFile, false);
        data.imagePaths = images;
        bitFnt = new BitmapFont(data,(TextureRegion) null,false);
    }

    @Override
    public void draw(Batch batch, float parentAlpha) {
        super.draw(batch, parentAlpha);
        Gdx.gl.glClearColor(1, 1, 1, 1);
        Gdx.gl.glClear(GL20.GL_COLOR_BUFFER_BIT);
        String txt = "我是小辉锦衣卫";
        bitFnt.setColor(Color.BLUE);
        bitFnt.draw(batch, txt, 500, 400);
    }
}






展开阅读全文

没有更多推荐了,返回首页