在我的andengine项目中的黑屏

时间:2015-11-26 08:32:19

标签: android andengine

在AndEngine中创建我的第一个应用程序时,我只得到一个黑屏而不是获取背景图像和播放按钮。 这里的代码 MainActivity

public class MainActivity extends BaseGameActivity {

private BoundCamera camera;
private float WIDTH = 800;
private float HEIGHT = 480;

@Override
public Engine onCreateEngine(EngineOptions engineOptions){
    return new LimitedFPSEngine(engineOptions,60);
}

@Override
public EngineOptions onCreateEngineOptions() {

    camera = new BoundCamera(0,0,WIDTH,HEIGHT);
    EngineOptions engineOptions = new
            EngineOptions(true, ScreenOrientation.LANDSCAPE_FIXED, new FillResolutionPolicy(),camera);
    engineOptions.getAudioOptions().setNeedsMusic(true).setNeedsSound(true);
    return engineOptions;
}

@Override
public void onCreateResources(OnCreateResourcesCallback pOnCreateResourcesCallback) throws IOException {

}

@Override
public void onCreateScene(OnCreateSceneCallback pOnCreateSceneCallback) throws IOException {

}

@Override
public void onPopulateScene(Scene pScene, OnPopulateSceneCallback pOnPopulateSceneCallback) throws IOException {

}
}

BaseScene.java

public abstract class BaseScene extends Scene {

protected Engine engine;
protected Activity activity;
protected ResourceManager resourceManager;
protected VertexBufferObjectManager vbom;
protected Camera camera;

public BaseScene(){
    this.resourceManager = ResourceManager.getInstance();

    this.activity = resourceManager.activity;
    this.engine = resourceManager.engine;
    this.vbom = resourceManager.vbom;
    this.camera = resourceManager.camera;

    createScene();
}

public abstract void createScene();
public abstract void onBackKeyPressed();
public abstract SceneManager.SceneType getSceneType();
public abstract void disposeScene();
}

SceneManager.java

public class SceneManager {

private BaseScene mainMenu;
private BaseScene gameScene;

private BaseScene currentScene;

private static final SceneManager INSTANCE = new SceneManager();

private SceneType currentSceneType = SceneType.SCENE_MENU;

private Engine engine = ResourceManager.getInstance().engine;

public enum SceneType
{
    SCENE_MENU,
    SCENE_GAME
}

public void setScene(BaseScene scene){

    engine.setScene(scene);

    currentScene = scene;

    currentSceneType = scene.getSceneType();

}

public static SceneManager getInstance(){
    return INSTANCE;
}

public SceneType getSceneType(){
    return currentSceneType;
}
}

我还有2个类MainMenu和ResourceManager 我哪里出错?

2 个答案:

答案 0 :(得分:1)

当纹理(图像)的大小超过bitMapTextureAtlus时,会出现黑屏。所以请确保您正在加载所需大小的bitMapTextureAtlus。

答案 1 :(得分:1)

最低限度你应该在游戏活动的超类中实现4个回调方法。

  • onCreateEngineOptions:您应该在哪里指定游戏引擎的主要特征。 (例如相机,渲染选项,声音选项)

  • onCreateResources:你应该在游戏发布后立即加载你需要立即使用的纹理和声音。

  • onCreateScene:你应该在哪里实例化游戏的第一个场景。每当用户开始游戏时,引擎都会显示此游戏。

  • onPopulateScene:实现此回调是可选的,取决于您的设计架构。但是,您应该调用给定的回调以让引擎继续运行。

在这些方法中,您获得了pOnCreateSceneCallback个对象。在您使用该方法完成后,应调用此对象。您必须这样做,否则您的引擎会卡住并且无法加载您的游戏。

AndEngine入门