2015-04-01 31 views
0

对不起,如果这个问题之前被问到。我已经搜索过,但我没有找到任何关于此的线索,所以我在这里发布问题。AnimatedSprite显示大小错误

我真的是Andengine的新手。我正在尝试加载一个平铺雪碧,并用它创建一个动画。 这里是我的代码:

public void loadGameResources() { 
    BitmapTextureAtlasTextureRegionFactory.setAssetBasePath("gfx/player/"); 
    mSapoTextureAtlas = new BitmapTextureAtlas(mActivity.getTextureManager(),256,178,TextureOptions.DEFAULT); 
    mPlayerDownITiledTextureRegion = BitmapTextureAtlasTextureRegionFactory.createTiledFromAsset(mPlayerTextureAtlas, mActivity.getAssets(), "player.png", 0,0,3,1); 
    mPlayerTextureAtlas.load(); 

} 

我想到的是,玩家可以像走了一些行动,但我不知道。请参阅附件截图以查看实际结果。我认为我的代码将原始纹理分成3部分,而不是在第一行分割3个精灵。

请看看并帮我解决这个问题。非常感谢!

enter image description here enter image description here enter image description here enter image description here 这里是我如何创建动画:

AnimatedSprite player= new AnimatedSprite(100,100,40,40,mResourceManager.mPlayerDownITiledTextureRegion,mVertexBufferObjectManager); 
player.animate(500); 
player.setZIndex(100); 
attachChild(sapo); 

回答

1

我明白了什么是要正确的动画效果在每个方向上的球员。对于

据库方法

BitmapTextureAtlasTextureRegionFactory.createTiledFromAsset(pBitmapTextureAtlas,pAssetManager,pAssetPath,pTextureX,pTextureY,pTileColumns,pTileRows);

您的代码将如下

mSapoTextureAtlas = new BitmapTextureAtlas(mActivity.getTextureManager(),256,256,TextureOptions.DEFAULT); 
mPlayerDownITiledTextureRegion = BitmapTextureAtlasTextureRegionFactory.createTiledFromAsset(mPlayerTextureAtlas, mActivity.getAssets(), "player.png", 0,0,3,4); 

要动画在不同的方向改变玩家使用这种技术 定义数组作为

long[] ANIMATE_DURATION = new long[] { 200, 200, 200 }; 

AnimatedSprite player = new AnimatedSprite(x, y, this.mPlayerTextureRegion,this.getVertexBufferObjectManager()); 



// Down 
player.animate(ANIMATE_DURATION, 0, 2, true); 
// Up 
player.animate(ANIMATE_DURATION, 9, 11, true); 
// Right 
player.animate(ANIMATE_DURATION, 6, 8, true); 
// Left 
player.animate(ANIMATE_DURATION, 3, 5, true); 

看看这个Example以获取更多信息。

如果你有疑问问我。希望这有助于!

+0

谢谢你的回应,Harry。我已经按照你的描述编辑了我的代码,但没有任何变化。我会深入研究一下。 – 2015-04-01 12:43:13

+0

请参阅编辑答案,您需要在玩家精灵中加载行数和列数的纹理。 – Harry 2015-04-01 12:52:22

+0

非常感谢你,哈利。现在问题解决了。我必须加载整个地图集,而不是只加载一行。 – 2015-04-01 14:36:09

0

第一:图集应该是两位的权力,所以将其改为256x256。 二:

mPlayerDownITiledTextureRegion = BitmapTextureAtlasTextureRegionFactory.createTiledFromAsset(mPlayerTextureAtlas, mActivity.getAssets(), "player.png", 0,0,3,1); 

最后两位数字说,你有多少行和列有。你宣布了​​3列和1行。

三:Zindex在100是必需的,只有当你有这么多层。如果不是,你不需要它。