Android 而且发动机的结构很奇怪
有人知道为什么会这样吗 加载图像的代码:Android 而且发动机的结构很奇怪,android,textures,andengine,Android,Textures,Andengine,有人知道为什么会这样吗 加载图像的代码: gameOverAtlas = new BuildableBitmapTextureAtlas( activity.getTextureManager(), 1024, 1024, TextureOptions.DEFAULT); deathScreen1 = BitmapTextureAtlasTextureRegionFactory .createFr
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);
}
}
我得到这个错误:
看起来您在构建纹理图集之前调用了loadTexture 移动: 在try/Catch块之后 此外,如果纹理的大小与TextureTas的尺寸相同,则除非将“填充”和“间距”参数设置为0,否则将失败 另一方面,如果要制作仅包含单个纹理区域的纹理图集,则无需使用可构建的纹理图集
BuildableTexture atlas的特殊功能是,它可以将许多区域放入atlas中,这意味着您不需要使用TexturePacker和teh TexturePacker extension for andengine之类的程序 因为它是可构建的纹理,而不是普通的纹理,所以加载它的方式有点不同
try
{
gameTexture.build(new BlackPawnTextureAtlasBuilder<IBitmapTextureAtlasSource, BitmapTextureAtlas>(0, 0, 1));
gameTexture.load();
}
catch (TextureAtlasBuilderException e)
{
Debug.e(e);
}
试试看
{
gameTexture.build(新的BlackPawnTextureArtalasBuilder(0,0,1));
gameTexture.load();
}
捕捉(纹理LasBuilderException e)
{
e(e);
}
请记住最后3个参数,您可以控制填充等。我看不出您的代码中有任何错误。您是否总是使用
BuildableBitmapTextureAtlas
,或者为什么不只使用BitmapTextureAtlas
?但这不可能。之后如何加载atlas(gameOverAtlas.load()
)?唯一的情况下,我得到一个扭曲的图像像你一样,是当地图集没有正确加载或纹理太大的地图集。但是应用程序总是抛出一个异常。编辑以包括我如何加载它。上面,您在代码示例中省略了使用可构建纹理图集的“构建”部分。你打过电话吗?没有它就不能工作。不是“load()”而是“build()”,奇怪的地方现在不再是他们的,而是所有构建纹理的黑盒子——我知道这个错误。您的纹理图集不大于您的纹理。记住要考虑填充和间距。为了好玩,试着把它做成1048x1048。让我们
engine.getTextureManager().loadTexture(
this.gameOverAtlas);
engine.getTextureManager().loadTexture(
this.mAutoParallaxBackgroundTexture);
engine.getTextureManager().loadTexture(
this.gameOverAtlas);
try
{
gameTexture.build(new BlackPawnTextureAtlasBuilder<IBitmapTextureAtlasSource, BitmapTextureAtlas>(0, 0, 1));
gameTexture.load();
}
catch (TextureAtlasBuilderException e)
{
Debug.e(e);
}