【问题标题】:Loading multiple textures in an array in Android Andengine在 Android Andengine 中的数组中加载多个纹理
【发布时间】:2023-03-20 21:49:01
【问题描述】:

我正在使用一个 for 循环来实现 Sprite 对象的加载和处理,以便在一个刽子手游戏的键盘上显示。循环进行到第 4 次迭代并崩溃。它给我的错误说:

Texture must not exceed the bounds of the atlas

这实际上应该可以工作,因为所有图像都是 64x64 并且图集是这样声明的:

this.mAtlas[i] = new BitmapTextureAtlas(this.getTextureManager(),256, 256,TextureOptions.BILINEAR);

我正在使用一组图集和一组纹理来加载图像并加载图集。之后,我将纹理传递给实现精灵的自定义类。最后我将加载的精灵附加到场景中。这是循环的完整代码:

for(int i = 0; i < 28; i++)
{
    String name = Integer.toString(i);
    name+= ".png";
    this.mAtlas[i] = new BitmapTextureAtlas(this.getTextureManager(),256, 256,TextureOptions.BILINEAR);
    this.mTexture[i] = BitmapTextureAtlasTextureRegionFactory.createFromAsset(this.mAtlas[i], this, name, (i*64) + 5,0);
    this.mAtlas[i].load();
    if(i % 13 == 0)
    {               
        yPos -= 64;
    }
    if(i < 26)
    {
        letterPass = alphabet.substring(i);
    }
    else if(i == 26)
    {
        letterPass = "BackSpace";
    }
    else if(i == 27)
    {
        letterPass = "return";
    }
    letters[i] = new Letter((i * 64)+ 5.0f, yPos, this.mTexture[i].getHeight(), this.mTexture[i].getHeight(), this.mTexture[i], this.mEngine.getVertexBufferObjectManager());
    letters[i].setLetter(letterPass);
    mScene.attachChild(letters[i]);     
}

发生崩溃的那一行是:

this.mTexture[i] = BitmapTextureAtlasTextureRegionFactory.createFromAsset(this.mAtlas[i], this, name, (i*64) + 5,0);

我似乎无法弄清楚它为什么会崩溃,如果能提供任何帮助,我将不胜感激

【问题讨论】:

    标签: android arrays textures loading andengine


    【解决方案1】:

    您的纹理图集大小为 256x256 像素。你的精灵是 64x64 像素,你为每个精灵创建了一个图集……这意味着你浪费了很多空间。它甚至不起作用,因为在这一行:

        this.mTexture[i] = BitmapTextureAtlasTextureRegionFactory.createFromAsset(this.mAtlas[i], this, name, (i*64) + 5,0);
    

    您正在将纹理放置到 atlas 的位置 [i * 64 + 5, 0]。我敢打赌它在第四个纹理上失败了。 3 * 64 + 5 +64 = 261,你越界了。

    【讨论】:

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