我是Andengine的新手(GLES 2.0),我编写了代码来在我的设备屏幕上显示文字,但它似乎不起作用。
这是我的代码:
public class MainActivity extends BaseGameActivity {
final float Width = 480;
final float Height = 320;
Scene mScene;
Font mFont;
它扩展了Andengine的BaseGameActivity,因此第一部分是为andengine创建一个EngineOptions对象来创建Engine对象。
@Override
public EngineOptions onCreateEngineOptions() {
// TODO Auto-generated method stub
Camera camera = new Camera(Width/2, Height/2, Width, Height);
EngineOptions eo = new EngineOptions(true, ScreenOrientation.LANDSCAPE_FIXED,new RatioResolutionPolicy(480,320), camera);
return eo;
}
在第二部分中,创建了一个FPS限制引擎。
@Override
public Engine onCreateEngine(EngineOptions pEngineOptions) {
/* The returned super method simply calls:
return new Engine(pEngineOptions);
*/
return new LimitedFPSEngine(pEngineOptions,60);
}
接下来,我在onCreateResources函数中加载字体对象。
@Override
public void onCreateResources(OnCreateResourcesCallback onCreateResourcesCallback)
throws IOException {
// TODO Auto-generated method stub
// load font
mFont = FontFactory.create(mEngine.getFontManager(),
mEngine.getTextureManager(), 256, 256,
Typeface.create(Typeface.DEFAULT, Typeface.NORMAL), 32f,
true);
mFont.load();
onCreateResourcesCallback.onCreateResourcesFinished();
}
然后,我创建了场景并注册了一个FPSLogger。
@Override
public void onCreateScene(OnCreateSceneCallback onCreateSceneCallback) throws IOException {
// TODO Auto-generated method stub
mEngine.registerUpdateHandler(new FPSLogger());
mScene = new Scene();
mScene.setBackground(new Background(0f,0f,0.827f));
onCreateSceneCallback.onCreateSceneFinished(mScene);
}
这是我的问题:我创建了一个文本对象并将其附加到场景中:
@Override
public void onPopulateScene(Scene scene, OnPopulateSceneCallback onPopulateSceneCallback)
throws IOException {
// TODO Auto-generated method stub
// prepare letters
mFont.prepareLetters("Time: 1234567890".toCharArray());
Text mTimeText = new Text(100, 36, mFont, "Time:"
+ "1234", 30, mEngine.getVertexBufferObjectManager());
scene.attachChild(mTimeText);
mTimeText.setColor(0, 0, 1);
onPopulateSceneCallback.onPopulateSceneFinished();
}
}
......但没有任何反应。我的屏幕上只显示蓝色背景。有人可以帮忙吗?