AndEngine can not shows sprite

60 Views Asked by At

In Android Studio, I'm trying to create a sprite with AndEngine, but it failed to display the sprite, it only shows a black screen. I'v searched and tried different methods for hours.

Here is the structure:

-myApplication 
   -andEngine
   -app
      -res
         -drawable
             -stand.png

Here is the codes:

@Override
    public void onCreateResources() {

        this.mBitmapTextureAtlas = new BitmapTextureAtlas(getTextureManager(), 30, 30, TextureOptions.DEFAULT);
        mPlayerTextureRegion = BitmapTextureAtlasTextureRegionFactory.createFromResource(mBitmapTextureAtlas, this, R.drawable.stand, 0, 0);
        mBitmapTextureAtlas.load();

    }

    @Override
    public Scene onCreateScene() {
        this.mEngine.registerUpdateHandler(new FPSLogger()); 

        this.mMainScene = new Scene();
        this.mMainScene.setBackground(new Background(1, 1, 1));

        final Sprite oPlayer = new Sprite(100, 100, mPlayerTextureRegion, getVertexBufferObjectManager());
        this.mMainScene.attachChild(oPlayer);

        return this.mMainScene;
    }

Any help will be appreciated

Thanks.

1

There are 1 best solutions below

1
AAryan On

Check your logcat it's may be an exception.

As I check your code, this line may be reason of exception.

mPlayerTextureRegion = BitmapTextureAtlasTextureRegionFactory.createFromResource(mBitmapTextureAtlas, this, R.drawable.stand, 0, 0);

Check dimension of your stand.png it should not greater than 30*30 otherwise pass greater value, when you're creating object of BitmapTextureAtlas.