您好我刚开始使用AndEngine。我一直在使用教程here。我认为这很简单,但我似乎无法让它正常工作。目的只是显示一个简单的Sprite。我完全按照教程的指示编写了代码,但是当我运行游戏时,根本没有任何负载。我扔了一些Log.i语句,似乎没有任何基本方法(OnCreateResources等...)运行。我没有收到任何错误但是没有任何错误。有谁知道我做错了什么?
(我希望这不是一个愚蠢的问题)代码如下:
public class GameMain extends BaseGameActivity {
Scene scene;
protected static final int CAMERA_WIDTH = 800;
protected static final int CAMERA_HEIGHT = 480;
BitmapTextureAtlas playerTexture;
ITextureRegion playerTextureRegion;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_game_main);
Log.i("TEST", "CREATE GAME");
}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.game_main, menu);
return true;
}
@Override
public EngineOptions onCreateEngineOptions() {
// TODO Auto-generated method stub
Camera mCamera = new Camera(0, 0, CAMERA_WIDTH, CAMERA_HEIGHT);
EngineOptions options = new EngineOptions(true,
ScreenOrientation.LANDSCAPE_FIXED, new RatioResolutionPolicy(
CAMERA_WIDTH, CAMERA_HEIGHT), mCamera);
return options;
}
@Override
public void onCreateResources(
OnCreateResourcesCallback pOnCreateResourcesCallback)
throws Exception {
// TODO Auto-generated method stub
Log.i("TEST", "LOADING GFX");
loadGFX();
pOnCreateResourcesCallback.onCreateResourcesFinished();
}
private void loadGFX() {
// TODO Auto-generated method stub
Log.i("TEST", "LOAD GFX");
BitmapTextureAtlasTextureRegionFactory.setAssetBasePath("gfx/");
playerTexture = new BitmapTextureAtlas(getTextureManager(), 64, 64);
playerTextureRegion = BitmapTextureAtlasTextureRegionFactory
.createFromAsset(playerTexture, this, "star.png", 0, 0);
playerTexture.load();
}
@Override
public void onCreateScene(OnCreateSceneCallback pOnCreateSceneCallback)
throws Exception {
// TODO Auto-generated method stub
Log.i("TEST", "Scene Background");
this.scene = new Scene();
this.scene.setBackground(new Background(0, 125, 58));
pOnCreateSceneCallback.onCreateSceneFinished(this.scene);
}
@Override
public void onPopulateScene(Scene pScene,
OnPopulateSceneCallback pOnPopulateSceneCallback) throws Exception {
// TODO Auto-generated method stub
Sprite sPlayer = new Sprite(CAMERA_WIDTH / 2, CAMERA_HEIGHT / 2,
playerTextureRegion,
this.mEngine.getVertexBufferObjectManager());
sPlayer.setRotation(45.0f);
this.scene.attachChild(sPlayer);
pOnPopulateSceneCallback.onPopulateSceneFinished();
}
}
答案 0 :(得分:1)
简要介绍一下教程,我没有看到任何关于覆盖onCreate
方法的内容,尤其是。 setContentView
部分可能是错误的。
让我想知道,您的日志中没有Log.i
次调用,您是否将日志设置为高于信息的级别?
让我深入了解一下,如果这两个提示不正确的话; - )