请帮帮我,我的代码中的错了吗?在设备上显示黑色背景。
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 :(得分:3)
我有一些修复方法:
Scene(int)
,已弃用。请改用Scene()
。scene.setBackground(new SpriteBackground(backLayer));
,而不是scene.getTopLayer().addEntity(backLayer);
。最后,我在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);