我是 AndEngine 的新手,我正在尝试使用一个菜单创建一个场景,其中只有一个按钮项,其中仅包含一个标签。
这是代码
public class TestActivity extends SimpleBaseGameActivity implements IOnMenuItemClickListener
{
static final int CAMERA_WIDTH = 800;
static final int CAMERA_HEIGHT = 480;
Camera mCamera;
@Override
public EngineOptions onCreateEngineOptions()
{
mCamera = new Camera(0, 0, CAMERA_WIDTH, CAMERA_HEIGHT);
return new EngineOptions(true,
ScreenOrientation.LANDSCAPE_SENSOR,
new RatioResolutionPolicy(CAMERA_WIDTH, CAMERA_HEIGHT),
mCamera);
}
@Override
protected void onCreateResources()
{
// TODO Auto-generated method stub
}
@Override
protected Scene onCreateScene()
{
//Scene scene = new Scene();
//scene.setBackground(new Background(0.09804f, 0.6274f, 0));
//Entity layer = new Entity();
//scene.attachChild(layer);
Font mFont = FontFactory.create(this.getFontManager(),
this.getTextureManager(),
256, 256,
Typeface.create(Typeface.DEFAULT, Typeface.BOLD),
32);
mFont.load();
//Text centerText = new Text(100, 40, mFont, "Hello AndEngine!\nYou can even have multilined text!", new TextOptions(HorizontalAlign.CENTER), this.getVertexBufferObjectManager());
//layer.attachChild(centerText);
TextMenuItem playText = new TextMenuItem(1, mFont, "TEXT_TO_DISPLAY",
this.getVertexBufferObjectManager());
MenuScene ms = new MenuScene();
ms.addMenuItem(playText);
ms.setBackground(new Background(0.09804f, 0.6274f, 0));
//ms.buildAnimations();
//ms.setBackgroundEnabled(false);
ms.setOnMenuItemClickListener(this);
//scene.attachChild(ms);
return ms;
}
@Override
public boolean onMenuItemClicked(MenuScene pMenuScene, IMenuItem pMenuItem,
float pMenuItemLocalX, float pMenuItemLocalY)
{
// TODO Auto-generated method stub
return false;
}
}
应用程序崩溃,我不知道如何修复它
这是日志猫堆栈跟踪
11-09 07:57:17.670: E/dalvikvm(3960): GC_EXPLICIT freed 186K, 42% free 8192K/13955K, paused 21ms+64ms, total 212ms
11-09 07:57:17.900: E/dalvikvm(3960): GC_EXPLICIT freed 68K, 42% free 8172K/13955K, paused 118ms+33ms, total 179ms
11-09 07:57:17.910: W/dalvikvm(3960): threadid=13: thread exiting with uncaught exception (group=0x4187c438)
我注意到如果我取消注释 buildAnimations() 我会得到一个 nullPointer 异常