2011-11-27 64 views
0

請幫助我,我的代碼中的錯誤?在設備上顯示黑色背景。AndEngine現場加載資源

public void onLoadResources() 
{ 

    this.mTexture = new Texture(1024, 1024); 
    this.mTextureRegion = TextureRegionFactory.createFromAsset(this.mTexture, this, "gfx/bgr.png",0,0); 
    this.getEngine().getTextureManager().loadTexture(this.mTexture); 
} 

@Override 
public Scene onLoadScene() 
{ 
    final Scene scene = new Scene(1); 
    backLayer=new Sprite(0,0,this.mTextureRegion); 
    scene.getTopLayer().addEntity(backLayer); 
    return scene; 
} 
+0

我建議去了[AndEngine論壇](http://www.andengine.org/forums),並通過一些教程和實例的期待。 – jmcdale

回答

3

我有幾個修復您:

  1. 不要使用構造Scene(int),其棄用。改爲使用Scene()
  2. 通過你的精靈名字,我猜這是你的場景背景?如果這是你的意圖,你應該使用這個:scene.setBackground(new SpriteBackground(backLayer));,而不是scene.getTopLayer().addEntity(backLayer);
  3. 最後,我沒有在TextureRegionFactory中看到方法createFromAsset。也許你應該更新你的AndEngine類?而是試試這個,可能工作:

    BitmapTextureAtlas textureAtlas = new BitmapTextureAtlas(1024, 256, TextureOptions.BILINEAR_PREMULTIPLYALPHA); 
    BitmapTextureAtlasTextureRegionFactory.setAssetBasePath("gfx/");  
    this.mTextureRegion = BitmapTextureAtlasTextureRegionFactory.createFromAsset(textureAtlas, this, "bgr.png", 0, 0);