【问题标题】:AndEngine Texture very strangeAndEngine Texture 很奇怪
【发布时间】:2013-03-18 19:25:32
【问题描述】:

有人知道为什么会这样吗?

加载图片的代码:

 gameOverAtlas = new BuildableBitmapTextureAtlas(
                activity.getTextureManager(), 1024, 1024,
                TextureOptions.DEFAULT);

deathScreen1 = BitmapTextureAtlasTextureRegionFactory
                .createFromAsset(gameOverAtlas, activity,
                        "deathscreen1.png");

engine.getTextureManager().loadTexture(
            this.gameOverAtlas);
    engine.getTextureManager().loadTexture(
            this.mAutoParallaxBackgroundTexture);
    engine.getTextureManager().loadTexture(
            this.gameOverAtlas);

    try {
        this.gameTextureAtlas
                .build(new BlackPawnTextureAtlasBuilder<IBitmapTextureAtlasSource, BitmapTextureAtlas>(
                        0, 1, 0));
        this.gameTextureAtlas.load();

        this.gameOverAtlas
                .build(new BlackPawnTextureAtlasBuilder<IBitmapTextureAtlasSource, BitmapTextureAtlas>(
                        0, 1, 0));
        this.gameOverAtlas.load();

        this.playerAtlas
                .build(new BlackPawnTextureAtlasBuilder<IBitmapTextureAtlasSource, BitmapTextureAtlas>(
                        0, 1, 0));
        this.playerAtlas.load();

    } catch (final TextureAtlasBuilderException e) {
        Debug.e(e);
    }
}

然后附加精灵:

gameOverScreen =  new Sprite(0, 0, 650, 400, ResourceManager.getInstance().deathScreen1,vbom);

    attachChild(gameOverScreen);    

我收到此错误:

【问题讨论】:

  • 我在你的代码中看不到任何错误。你总是使用BuildableBitmapTextureAtlas 还是为什么不只使用BitmapTextureAtlas?但这不可能。之后如何加载图集(gameOverAtlas.load())?我得到像你这样扭曲的图像的唯一情况是图集没有正确加载或纹理对于图集来说太大了。但随后应用程序总是抛出异常。
  • 已编辑以包括我如何加载它。

标签: android textures andengine


【解决方案1】:

看起来您在构建纹理图集之前调用了 loadTexture。

移动:

engine.getTextureManager().loadTexture(
        this.gameOverAtlas);
engine.getTextureManager().loadTexture(
        this.mAutoParallaxBackgroundTexture);
engine.getTextureManager().loadTexture(
        this.gameOverAtlas);

在 try/Catch 块之后。

此外,如果您的纹理与 TextureAltas 的尺寸相同,除非您将填充和间距参数设置为 0,否则它将失败。

顺便说一句,如果您正在制作仅包含单个纹理区域的纹理图集,则无需使用可构建的纹理图集。

BuildableTexture 地图集的特殊之处在于它可以将许多区域适合您到地图集中,这意味着您不需要使用诸如 TexturePacker 之类的程序和用于 andengine 的 texturePacker 扩展。

【讨论】:

  • 在上面,您在代码示例中省略了使用可构建纹理图集的“构建”部分。你有没有打电话给它?没有它就行不通。不是“load()”而是“build()”
  • 现在的怪异不再是它们,而是所有构建纹理的黑匣子
  • 哦 - 我知道那个错误。您的纹理图集不大于您的纹理。记住要考虑填充和间距。为了好玩,请尝试将其设为 1048x1048。
【解决方案2】:

由于它的纹理是可构建的,而不是普通的,所以你加载它的方式有点不同

try
{           
    gameTexture.build(new BlackPawnTextureAtlasBuilder<IBitmapTextureAtlasSource, BitmapTextureAtlas>(0, 0, 1));
    gameTexture.load();
}
catch (TextureAtlasBuilderException e)
{
    Debug.e(e);
}

记住最后三个参数,你可以控制填充等。

【讨论】:

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