2017-04-01 111 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