[英]AndEngine can not shows sprite
在Android Studio中,我嘗試使用AndEngine創建一個Sprite,但它無法顯示Sprite,它僅顯示黑屏。 我搜索並嘗試了數小時的其他方法。
結構如下:
-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;
}
任何幫助將不勝感激
謝謝。
檢查您的logcat,這可能是一個例外。
當我檢查您的代碼時,此行可能是異常原因。
mPlayerTextureRegion = BitmapTextureAtlasTextureRegionFactory.createFromResource(mBitmapTextureAtlas, this, R.drawable.stand, 0, 0);
在創建BitmapTextureAtlas
對象時,請檢查stand.png
尺寸,該尺寸不應大於30*30
否則傳遞更大的值。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.