AndEngine GLES2 |使字体可调整大小?

时间:2012-04-05 11:59:24

标签: fonts opengl-es-2.0 textures andengine resizable

我现在知道AndEngine中所有基本调整大小的东西,但我没有偶然发现如何使文本可调整大小。基本上每个人都在做的是所有字体都被声明为位图,让我们说18pt,并希望最好。在开发设备上,一切看起来都很清晰,但是当切换到更大的设备时,它看起来非常难看。我是否必须将所有字体加载到更大的Atlas中然后调整大小?这不是一个选择。请帮忙。

1 个答案:

答案 0 :(得分:2)

您的问题是GLES2特有的吗?我不这么认为。

字体大小不应随屏幕尺寸缩放,而应与密度一致。也许两者。无论如何。在FluxCards中我这样做:

// determine the density
WindowManager windowManager = (WindowManager) getSystemService(WINDOW_SERVICE);
Display display = windowManager.getDefaultDisplay();
DisplayMetrics displayMetrics = new DisplayMetrics();
display.getMetrics(displayMetrics);
density = displayMetrics.density;

// scale desired size 25 by density
int fontSize = (int) (25 * density);

Texture fontTexture = new BitmapTextureAtlas(1024, 1024, TextureOptions.BILINEAR_PREMULTIPLYALPHA);
font = new Font(fontTexture, Typeface.create(Typeface.DEFAULT, Typeface.NORMAL), fontSize, true, Color.WHITE);
mEngine.getTextureManager().loadTexture(fontTexture);
mEngine.getFontManager().loadFont(font);

(我的代码更复杂,我仍然很努力,因为1024x1024是我可以用于fontTexture的最大值,并且使用更大的字体和亚洲文本,有时候不会写字母。我正在搜索如何使用Text在GLES2和我的2分钟阅读之前,我遇到了你的问题,这表明这不再是一个问题了。)