0

您好,我刚刚开始使用 AndEngine。我一直在这里使用教程。我认为这很简单,但我似乎无法让它正常工作。目的只是显示一个简单的 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();

}

}
4

1 回答 1

1

简短地看一下教程,我没有看到任何关于覆盖onCreate方法的内容,尤其是。该setContentView部分可能是错误的。

让我想知道,Log.i您的日志中没有出现任何呼叫,您是否将日志设置为比信息更高的级别?

让我更深入地研究一下,如果这两个提示不正确;-)

于 2013-07-22T21:21:32.983 回答