AndEngine场景加载资源

发布于 2024-12-18 09:11:08 字数 510 浏览 0 评论 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;
}

Help me please, wat's wrong in my code? 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;
}

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

热情消退 2024-12-25 09:11:08

我为您提供了一些解决方案:

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

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

I have a few fixes for you:

  1. Don't use the constructor Scene(int), its deprecated. Use Scene() instead.
  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));, instead of scene.getTopLayer().addEntity(backLayer);.
  3. Lastly, I didn't see the method createFromAsset in TextureRegionFactory. Maybe you should update your AndEngine classes? 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);
    
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文