【问题标题】:AndEngine scene load resourcesAndEngine场景加载资源
【发布时间】:2011-11-27 13:24:25
【问题描述】:

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

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

【问题讨论】:

标签: android layer andengine scene


【解决方案1】:

我有一些解决方法:

  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);
    

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多