2017-04-01 181 views
0

在Android Studio中,我試圖用AndEngine創建一個精靈,但它未能顯示精靈,它只顯示黑屏。我搜索並嘗試了幾個小時的不同方法。AndEngine無法顯示精靈

下面是結構:

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

這裏是代碼:

@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; 
    } 

任何幫助將理解

感謝。

回答

0

檢查你的logcat它可能是一個例外。

當我檢查你的代碼時,這一行可能是異常的原因。

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

檢查的尺寸您stand.png應不大於30*30否則通過更大的價值,當你創建的BitmapTextureAtlas對象。

+1

我已經用JBox2d完成了遊戲,如果我有時間我可以再次用AndEngine測試它,謝謝無論如何。 – jdleung