0

I am new to AndEngine Game Development. I am trying to load and display a single sprite , But i got blank blcak screen without sprite on the screen. Here is the code:

public class MainActivity extends SimpleBaseGameActivity {

static final int CAMERA_WIDTH = 800; 
static final int CAMERA_HEIGHT = 480;

private static final String TAG = "AndEngineTest";
private BitmapTextureAtlas mBitmapTextureAtlas;
private TextureRegion mPlayerTextureRegion;

@Override
public EngineOptions onCreateEngineOptions() {

    Camera mCamera = new Camera(0, 0, CAMERA_WIDTH , CAMERA_HEIGHT);
    return new EngineOptions(true,ScreenOrientation.LANDSCAPE_SENSOR, 
            new RatioResolutionPolicy(CAMERA_WIDTH, CAMERA_HEIGHT), mCamera);

}

@Override
protected void onCreateResources() {
    mBitmapTextureAtlas = new BitmapTextureAtlas(this.getTextureManager(), 32, 32,
            TextureOptions.BILINEAR_PREMULTIPLYALPHA);
    mPlayerTextureRegion = BitmapTextureAtlasTextureRegionFactory.createFromAsset(this.mBitmapTextureAtlas, this, "gfx/face_box.png", 0, 0);
    mBitmapTextureAtlas.load();
}

@Override
protected Scene onCreateScene() {

    this.mEngine.unregisterUpdateHandler(new FPSLogger());

    Scene scene = new Scene();
    scene.setBackground(new Background(3f, 6f, 2f));
    Sprite Player = new Sprite(32, 32, mPlayerTextureRegion, getVertexBufferObjectManager());
    Camera mCamera = new Camera(0, 0, CAMERA_WIDTH , CAMERA_HEIGHT);
    Player.setPosition(mCamera.getWidth()/2 - Player.getWidth()/2,
            mCamera.getHeight() - Player.getHeight() - 10);
    scene.attachChild(Player);



    return scene;
}

Can anyone tell what is the mistake here ??? Any useful help will be appreciaed .

Stack
  • 5
  • 3

1 Answers1

0

You have a few issues with your code:

  1. Change unregisterUpdateHandler to registerUpdateHandler
  2. Your Camera and Sprite could/should be global variables referenced from the methods they are used in.
  3. Change Player to player (this is just a convention but is useful to follow).
  4. When you initialise player the first 2 parameters are the position not the size - this will save you having to make the extra method call to setPosition().
  5. Write BitmapTextureAtlasTextureRegionFactory.setAssetBasePath("gfx/"); at the beginning of onCreateResources() and change "gfx/face_box.png" to "face_box.png".

1,2 and 4 are pretty much essential, 3 and 5 are optional but I would recommend them to simplify things.

Does this solve the problem?

Uwais A
  • 737
  • 6
  • 23