AndEngine获取错误:提供的pTextureAtlasSource不得超过Texture的边界

时间:2011-12-21 11:43:49

标签: android andengine

我是Android游戏的新手,在使用createTiledFromAsset时启动了andengine并面临问题 我遇到问题的代码是

@Override
public void onLoadResources() {
    mBitmapTextureAtlas = new BitmapTextureAtlas(128, 128,
            TextureOptions.BILINEAR);

    BitmapTextureAtlasTextureRegionFactory.setAssetBasePath("gfx/");

    mPlayerTextureRegion = BitmapTextureAtlasTextureRegionFactory
            .createTiledFromAsset(this.mBitmapTextureAtlas, this,
                    "move.png", 0, 0, 10, 1);
    mEngine.getTextureManager().loadTexture(mBitmapTextureAtlas);

}

@Override
public Scene onLoadScene() {
    mEngine.registerUpdateHandler(new FPSLogger());

    mMainScene = new Scene();
    mMainScene
            .setBackground(new ColorBackground(0.09804f, 0.6274f, 0.8784f));

    player = new AnimatedSprite(0, 0, mPlayerTextureRegion);

    mMainScene.attachChild(player);
    return mMainScene;
}

我没有得到错误,因为我的BitmapTextureAtlas是128 * 128并且来自createTiledFromAsset的每个平铺部分应该是78 * 85,因为传递给它的参数是1行10列,我的源图像是779 * 85这意味着当宽度被平铺到10个部分然后779/10 = 78大约是每个平铺部分的宽度并且因为行是1所以85/1 = 85因此每个平铺部分的宽度*高度将被放置在BitmapTextureAtlas上是78 * 85而BitmapTextureAtlas本身的大小是128 * 128那么为什么错误说Supplied pTextureAtlasSource must not exceed bounds of Texture 这里发生了什么......?或者我不了解实际的功能......?如果我错了那么createTiledFromAsset的过程如何工作........?

2 个答案:

答案 0 :(得分:5)

我也发现了同样的问题。我正在使用大型精灵表,并尝试使用它。在搜索之后,我在本教程中找到了一些线索:getting-started-working-with-images我意识到宽度和高度的值用于:

BitmapTextureAtlas(WIDTH, HEIGHT ,TextureOptions.BILINEAR);

必须高于图像尺寸。例如,如果我使用1200 * 100精灵表,我必须使用高于1200 * 100的宽度和高度。

BitmapTextureAtlas(2047, 128, TextureOptions.BILINEAR);

答案 1 :(得分:2)

如果我正确理解了BitmapTextureAtlas,你试图将779 * 85图像放入128 * 128的小空间。 TextureAtlas是一个大型画布,您应该在其上放置许多图像。稍后使用名为TextureRegion的对象访问这些图像,该对象基本上指定画布上较小图片的大小和坐标。 createTiledFromAsset方法可能会将原始图像1:1复制到TextureAtlas上并保存切片的坐标。

请注意,TextureRegion与图像本身无关,它只是指向存储图像的TextureAtlas上的位置的“指针”。

要了解TextureAtlas的实际情况,请查看本页底部的精彩图片: http://www.blackpawn.com/texts/lightmaps/default.html

相关问题