我是android游戏新手,开始使用andengine,在使用createTiledFromAsset时遇到了问题我遇到问题的代码是
@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的瓷砖宽度时然后779/10 = 78年大约10部分将每个瓷砖部分和行宽度是1 85/1 = 85因此宽*高的瓷砖部分放在BitmapTextureAtlas是78 * 85,BitmapTextureAtlas本身大小128*128,那么为什么错误说Supplied pTextureAtlasSource must not exceed bounds of Texture
这里发生了什么?或者我不理解实际的功能…?如果我错了,那么createTiledFromAsset的过程是如何工作的........?
我也发现了同样的问题。我正在使用一个大的精灵表,并尝试使用它。经过搜索,我在这个教程中找到了一些线索:开始使用图像,我意识到:
中使用的宽度和高度的值 BitmapTextureAtlas(WIDTH, HEIGHT ,TextureOptions.BILINEAR);
必须大于图像大小。例如,如果我使用1200*100的精灵表,我必须使用高于1200*100的宽度和高度。
BitmapTextureAtlas(2047, 128, TextureOptions.BILINEAR);
如果我正确理解BitmapTextureAtlas,你正试图将779*85的图像放入128*128的小空间。TextureAtlas是一个大画布,你可以在上面放置许多图像。这些图像稍后使用名为TextureRegion的对象进行访问,该对象基本上指定画布上较小图片的大小和坐标。createTiledFromAsset方法可能会将原始图像1:1地复制到TextureAtlas上,并保存贴图的坐标。
请注意,texturereregion与图像本身无关,它只是一个指向TextureAtlas中存储图像的位置的"指针"。
要了解什么是TextureAtlas,看看这个页面底部的一些很棒的图片:http://www.blackpawn.com/texts/lightmaps/default.html