简体   繁体   English

AndEngine场景加载资源

[英]AndEngine scene load resources

Help me please, wat's wrong in my code? 请帮帮我,我的代码中wat错误吗? On device shown black background. 在显示为黑色背景的设备上。

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

I have a few fixes for you: 我为您提供了一些解决方案:

  1. Don't use the constructor Scene(int) , its deprecated . 不要使用构造Scene(int)弃用 Use Scene() instead. 使用Scene()代替。
  2. By your sprite's name, I guess it is your scene background? 用您的精灵的名字,我想这是您的场景背景吗? If this is your intention, you should use this: scene.setBackground(new SpriteBackground(backLayer)); 如果您打算这样做,则应使用此方法: scene.setBackground(new SpriteBackground(backLayer)); , instead of scene.getTopLayer().addEntity(backLayer); ,而不是scene.getTopLayer().addEntity(backLayer); .
  3. Lastly, I didn't see the method createFromAsset in TextureRegionFactory . 最后,我没有看到的方法createFromAssetTextureRegionFactory Maybe you should update your AndEngine classes? 也许您应该更新AndEngine类? And try this instead, might work: 并尝试这样做,可能会起作用:

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM