AndEngine-GLES2 显示文本信息

来源:互联网 发布:淘宝卖家升级 编辑:程序博客网 时间:2024/05/16 11:05

在游戏开发中,必不可少的就是显示文本信息。先前从网上找到的是老版的AndEngine显示文本信息,我现在用的是新版的所以就没有用了。

于是,我在网上找了一下,介绍一下AndEngine-GLES2 怎么显示信息。

参考文章:

http://www.andengine.org/forums/post56656.html?hilit=FontFactory.create#p56656

http://www.cnblogs.com/kylin17/archive/2013/03/06/2946216.html


要现实文本需要在onCreateScene、onCreateScene这两个里面添加代码

代码只写关键部分

public void onCreateResources(OnCreateResourcesCallback pOnCreateResourcesCallback)throws Exception {//省略this.mFont = FontFactory.create(this.getFontManager(), this.getTextureManager(), 256, 256, Typeface.create(Typeface.DEFAULT, Typeface.BOLD),25,Color.WHITE.getABGRPackedInt());//最后一个参数不加会导致字体一直是黑色 this.mFont.load();//省略}

public void onCreateScene(OnCreateSceneCallback pOnCreateSceneCallback)throws Exception {mScene = new Scene();//系统原来代码mScene.setBackground(background);//系统原来代码Text centerText = new Text(100, 40,mFont, "Hello AndEngine!nYou can even have multilined text!",this.getVertexBufferObjectManager());//设置字体颜色centerText.setColor(Color.RED);centerText.setText("123");mScene.attachChild(centerText);//省略}


这只是最简单的显示文本信息,复杂的显示还有待继续研究。

0 0