【问题标题】:Basic Sprite not loading - AndEngine基本精灵未加载 - AndEngine
【发布时间】:2013-07-29 14:21:53
【问题描述】:

您好,我刚刚开始使用 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();

}

}

【问题讨论】:

    标签: android andengine sprite


    【解决方案1】:

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

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

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

    【讨论】:

    • 感谢您的回复。我注释掉了 onCreate 但随后整个屏幕变暗了。但是您似乎正确 onCreate 等似乎不在教程中。
    • 在这种情况下这没什么不好 - 你检查了你的日志级别并且仍然没有得到任何 logcat 条目吗?
    • 正确。我在所有方法周围放置了 Log 语句,并且没有 logcat 条目。
    • 测试了代码,它似乎可以正常工作 - 除了项目中的 GameMain 之外,您还有其他活动吗?您的 manifest.xml 是否在活动标签内使用 GameMain
    • 不,我没有。事实上,我实际上将教程源代码复制粘贴到我的项目中,然后屏幕就变黑了。我不知道发生了什么。
    猜你喜欢
    • 1970-01-01
    • 2014-04-27
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2014-03-14
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多