使用BitmapFont绘制字符串 [英] Draw string with BitmapFont

查看:99
本文介绍了使用BitmapFont绘制字符串的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

很抱歉这个愚蠢的问题,但我是一个安静的菜鸟.我不知道如何在Libgdx中绘制位图字体.好吧,我已经使用HIERO v2.0工具制作BitmapFont文件.然后我用代码初始化它:

Sorry for that stupid question but I'm a quiet noob. I can't figure out how to draw Bitmap Font in Libgdx. Well, I've used HIERO v2.0 tool to make BitmapFont file. Then I initialize it in code:

BitmapFont font = new BitmapFont(Gdx.files.internal("data/fonts/Georgia.fnt"), Gdx.files.internal("data/fonts/Georgia.png"), false);

但是当我尝试在屏幕上绘制时:

But when I try to draw it on screen:

game.batch.begin();    
font.draw(game.batch, "Text string", game.screenWidth * 0.5f, game.screenHeight * 0.5f);
game.batch.end();

我得到以下结果: http://imageshack.us/photo/my-images/696/bitmapfont.png/ 有人知道我在做什么错吗?

I get this result: http://imageshack.us/photo/my-images/696/bitmapfont.png/ Does anybody know, what I'm doing wrong?

推荐答案

当Georgia.fnt和Georgia.png不同步时,往往会发生这种情况.也就是说,它们来自不同的出口.

This tends to happen when the Georgia.fnt and Georgia.png are out of sync. That is, they are from different exports.

再次检查您是否同时将它们保存在HIERO中

Double check that you saved both in HIERO

这篇关于使用BitmapFont绘制字符串的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆