2011-11-27 65 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);