Reputation: 156
While creating my first app in AndEngine am getting only a black screen instead of getting the background image and play button.. Here the code 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;
}
}
I have 2 more classes MainMenu and ResourceManager Where did i go wrong?
Upvotes: 1
Views: 791
Reputation: 29285
Minimally you should implement 4 callbacks method from the superclass in your game activity.
onCreateEngineOptions
: Where you should specify main characteristics of your game engine. (e.g. camera, rendering options, sound options)
onCreateResources
: Where you should load textures and sounds that you need to use right away once your game is launched.
onCreateScene
: Where you should instantiate your game's first scene. This game will be shown by engine whenever user starts your game.
onPopulateScene
: Implementing this callback is optional and depends on what your design architecture is. However, you should call the given callback to let the engine to go ahead.
In these methods, you're given a pOnCreateSceneCallback
object. This object should be called once you're done in that method. You must do so, otherwise your engine gets stuck and won't load your game.
Getting started with AndEngine
Upvotes: 1
Reputation: 163
the black screen appears when texture(image) has more size than your bitMapTextureAtlus . so ensure that you are loading bitMapTextureAtlus with required size.
Upvotes: 1