【问题标题】:Andengine dynamic texture sometimes not loadingAndengine动态纹理有时不加载
【发布时间】:2014-01-21 08:31:38
【问题描述】:

我在动态加载纹理时遇到问题。

当用户双击屏幕时,背景和其他精灵会发生变化。没有产生错误,但有时纹理被清除并且新纹理没有加载。

这是我最初的 onCreateResource

ITextureRegion BackgroundTextureRegion;
BitmapTextureAtlas MainTexture1;

//Initiate Textures
MainTexture1 = new BitmapTextureAtlas(this.getTextureManager(),1000,1000, TextureOptions.BILINEAR);

//Clear Textures
MainTexture1.addEmptyTextureAtlasSource(0, 0, 1000,1000);

//Assign Image Files to TextureRegions
BackgroundTextureRegion = BitmapTextureAtlasTextureRegionFactory.createFromAsset(MainTexture1, this, "Evening.jpg",0,0);

//Loading the Main Texture to memory
MainTexture1.load();

在此之前没有问题。在此之后,当用户双击或滑动背景时,我会动态更改纹理。代码如下:

MainTexture1.clearTextureAtlasSources();
    MainTexture1.addEmptyTextureAtlasSource(0, 0, 1000,1000);
    BitmapTextureAtlasTextureRegionFactory.createFromAsset(MainTexture1, this, "WinterNight.jpg",0,0);

这通常会改变纹理,我会得到想要的结果。但在某些设备(例如三星 Tab 2)中,10 次中有 1 次 MainTexture1 被清除但未加载新图像。

所以它只是给出了一个黑屏,我该如何纠正这个问题?

【问题讨论】:

  • 你应该重新加载纹理吗?
  • 你的意思是 MainTexture1.load();再次?试过了。现在问题不像以前那样经常出现了。但仍然有 20 次中有 1 次变黑。谢谢。
  • 你在 LogCat 中没有例外吗? Andengine 有时会隐藏它。
  • 我的一个设备没有显示任何问题,问题出在其他一些设备(例如三星 tab2)现在我正在安装驱动程序以查看 logcat
  • No Logcat error found,没有错误,精灵只是不可见,如果我们采取任何设置或菜单并关闭它,精灵就会重新出现。

标签: android andengine


【解决方案1】:
MainTexture1.clearTextureAtlasSources();
 //   MainTexture1.addEmptyTextureAtlasSource(0, 0, 1000,1000);
BitmapTextureAtlasTextureRegionFactory.createFromAsset(MainTexture1, this, "WinterNight.jpg",0,0);
MainTexture1.load();

试试这个

【讨论】:

  • 我已经尝试过,正如我上面所说的,消失的问题得到了解决,但现在在某个时刻出现了一个小故障,就像图像中的一些垃圾或一些伪影,持续了大约 1/10 秒。现在我放置 MainTexture1.clearTextureAtlasSources();在第二行中,并在 First 上使用 addEmptyTextureAtlasSource,它看起来更好。但有时当我们快速双击时,有时会出现故障。
  • 另外我发现评论 addEmptyTextureAtlasSource() 会导致背景变化有点滞后。所以我重新安排了两者。但有时仍然存在故障。
  • 尝试在 Ui 线程中放置动态加载(即加载新图像..)数据。同时确保所有图像尺寸小于您正在使用的纹理
  • 这是怎么做到的?很好的纹理是 1000X1000 并且图像大小相同。这会是一个问题吗?
【解决方案2】:
      runOnUiThread(new Runnable() {
            @Override
            public void run() {
                MainTexture1.clearTextureAtlasSources();
   MainTexture1.addEmptyTextureAtlasSource(0, 0, 1024, 1024);
BitmapTextureAtlasTextureRegionFactory.createFromAsset(MainTexture1, this, "WinterNight.jpg",0,0);
MainTexture1.load();
            }
        });

像这样。

如果它不起作用,请尝试创建另一个纹理图集而不是相同的图集。

【讨论】:

    猜你喜欢
    • 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
    相关资源
    最近更新 更多