0

请帮助我,我的代码有什么问题吗?在显示黑色背景的设备上。

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

1 回答 1

3

我为您提供了一些修复:

  1. 不要使用构造函数Scene(int),它已弃用。改为使用Scene()
  2. 以你的精灵的名字,我猜这是你的场景背景?如果这是您的意图,您应该使用 this: scene.setBackground(new SpriteBackground(backLayer));,而不是scene.getTopLayer().addEntity(backLayer);.
  3. 最后,我没有看到createFromAsset. TextureRegionFactory也许你应该更新你的 AndEngine 类?试试这个,可能会奏效:

    BitmapTextureAtlas textureAtlas = new BitmapTextureAtlas(1024, 256, TextureOptions.BILINEAR_PREMULTIPLYALPHA);
    BitmapTextureAtlasTextureRegionFactory.setAssetBasePath("gfx/");    
    this.mTextureRegion = BitmapTextureAtlasTextureRegionFactory.createFromAsset(textureAtlas, this, "bgr.png", 0, 0);
    
于 2011-11-27T14:59:40.743 回答