我的andengine项目黑屏
Black screen in my andengine project
在 AndEngine 中创建我的第一个应用程序时,我只得到一个黑屏,而不是得到背景图像和播放按钮..
这里的代码
主要活动
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
我哪里错了?
当 texture(image) 的尺寸大于您的 bitMapTextureAtlus 时出现黑屏。因此请确保您正在加载所需大小的 bitMapTextureAtlus。
你至少应该在你的游戏中实现超类的 4 个回调方法 activity。
onCreateEngineOptions
:您应该在其中指定游戏引擎的主要特征。 (例如相机、渲染选项、声音选项)
onCreateResources
:游戏启动后,您应该加载需要立即使用的纹理和声音的位置。
onCreateScene
:您应该在哪里实例化游戏的第一个场景。每当用户启动您的游戏时,引擎都会显示该游戏。
onPopulateScene
:实现此回调是可选的,取决于您的设计架构。但是,您应该调用给定的回调让引擎继续。
在这些方法中,您得到了一个 pOnCreateSceneCallback
对象。完成该方法后,应调用该对象。您必须这样做,否则您的引擎会卡住,无法加载您的游戏。
开始使用 AndEngine
How to get started with andengine
在 AndEngine 中创建我的第一个应用程序时,我只得到一个黑屏,而不是得到背景图像和播放按钮.. 这里的代码 主要活动
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 我哪里错了?
当 texture(image) 的尺寸大于您的 bitMapTextureAtlus 时出现黑屏。因此请确保您正在加载所需大小的 bitMapTextureAtlus。
你至少应该在你的游戏中实现超类的 4 个回调方法 activity。
onCreateEngineOptions
:您应该在其中指定游戏引擎的主要特征。 (例如相机、渲染选项、声音选项)onCreateResources
:游戏启动后,您应该加载需要立即使用的纹理和声音的位置。onCreateScene
:您应该在哪里实例化游戏的第一个场景。每当用户启动您的游戏时,引擎都会显示该游戏。onPopulateScene
:实现此回调是可选的,取决于您的设计架构。但是,您应该调用给定的回调让引擎继续。
在这些方法中,您得到了一个 pOnCreateSceneCallback
对象。完成该方法后,应调用该对象。您必须这样做,否则您的引擎会卡住,无法加载您的游戏。
开始使用 AndEngine
How to get started with andengine