Hi I’m new in Android Developing.
I want to create an easy game using AndEngine. So I wanted to try a little sample. But when i deploy the apk-file to my nexus7. But when I run the App, it always says “Hello World” in the center of screen with White Background. But it should show an Image with specific Background Color.
Here’s my code:
public class MainActivity extends SimpleBaseGameActivity {
private static final float CAMERA_WIDTH = 720;
private static final float CAMERA_HEIGHT = 480;
private Camera mCamera;
private BitmapTextureAtlas mBitmapTextureAtlas;
private Engine mEngine;
private TextureRegion mFaceTextureRegion;
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
}
@Override
public EngineOptions onCreateEngineOptions() {
this.mCamera = new Camera(0, 0, CAMERA_WIDTH, CAMERA_HEIGHT);
return new EngineOptions(true,
ScreenOrientation.LANDSCAPE_FIXED, new RatioResolutionPolicy(
CAMERA_WIDTH, CAMERA_HEIGHT), mCamera);
}
@Override
protected void onCreateResources() {
this.mBitmapTextureAtlas = new BitmapTextureAtlas(
mEngine.getTextureManager(), 32, 32,
TextureOptions.BILINEAR_PREMULTIPLYALPHA);
BitmapTextureAtlasTextureRegionFactory.setAssetBasePath("gfx/");
this.mFaceTextureRegion = BitmapTextureAtlasTextureRegionFactory
.createFromAsset(this.mBitmapTextureAtlas, this,
"face_box.png", 0, 0);
getTextureManager().loadTexture(this.mBitmapTextureAtlas);
}
@Override
protected Scene onCreateScene() {
this.mEngine.registerUpdateHandler(new FPSLogger());
final Scene scene = new Scene();
scene.setBackground(new Background(new Color(0, 255, 128)));
final int centerX = (int) ((CAMERA_WIDTH - this.mFaceTextureRegion
.getWidth()) / 2);
final int centerY = (int) ((CAMERA_HEIGHT - this.mFaceTextureRegion
.getHeight()) / 2);
final Sprite face = new Sprite(centerX, centerY,
this.mFaceTextureRegion, new VertexBufferObjectManager());
scene.attachChild(face);
return scene;
}
}
What am I doing wrong? Thanks in advance.
Since you are using AndEngine SimpleBaseGameActivity, you don’t need this
“Hello world” shows up because you are setting the content view, remove the override to onCreate and it should work.