2011-02-12 74 views
1

我想在等轴测地图上的特定位置为精灵创建动画。我可以在一个给定的图层上对一个精灵进行动画处理,但是当它从一个地图上生成一个精灵时则不会。例如,下面的作品就好了:从瓦片贴图动画雪碧

// make a frame cache 
CCSpriteFrameCache *frameCache = [CCSpriteFrameCache sharedSpriteFrameCache]; 
[frameCache addSpriteFramesWithFile:@"spellanim.plist" textureFile:@"spellanim.pvr.ccz"]; 
// create a sprite 
CCSprite *effectSprite = [CCSprite spriteWithSpriteFrameName:@"spell_strength__33.png"]; 
// set sprite at center of screen 
CGSize screenSize = [[CCDirector sharedDirector] winSize]; 
effectSprite.position = CGPointMake(screenSize.width/2, screenSize.height/2); 
// create animation using an animation helper (since animationWithName:delay:frames: will be deprecated) 
CCAnimation *animation = [CCAnimation animationWithFrame:@"spell_strength__" frameCount:13 delay:0.3f startAt:33]; 
CCAnimate *animate = [CCAnimate actionWithAnimation:animation]; 
// run animation on sprite 
[effectSprite runAction:animate]; 
// add sprite as a child of the layer 
[self addChild:effectSprite]; 

现在下不工作,我认为它有多么瓷砖地图的工作(我在CCSprite的SetTexture得到一个断言失败做:):

// add one to x to offset the spell animation from the player 
CGPoint tileCoord = CGPointMake(player.entityTileCoordinate.x + 1, player.entityTileCoordinate.y); 
// get the effects layer from the tile map 
CCTMXTiledMap *tileMap = (CCTMXTiledMap *)[[TileMapLayer sharedTileMapLayer] getChildByTag:TileMapNode]; 
CCTMXLayer *effectsLayer = [tileMap layerNamed:@"Effects"]; 
// get a sprite from the effects layer 
CCSprite *effectSprite = [effectsLayer tileAt:CGPointMake(0, 0)]; 
// move the sprite to the desired location (this works just fine) 
CGPoint pointPixel = [effectsLayer positionAt:tileCoord]; 
[effectSprite runAction:[CCMoveTo actionWithDuration:0.0f position:pointPixel]]; 

// now animate the sprite 
CCSpriteFrameCache *frameCache = [CCSpriteFrameCache sharedSpriteFrameCache]; 
[frameCache addSpriteFramesWithFile:@"spellanim.plist" textureFile:@"spellanim.pvr.ccz"]; 
CCAnimation *animation = [CCAnimation animationWithFrame:@"spell_strength__" frameCount:13 delay:0.3f startAt:33]; 
CCAnimate *animate = [CCAnimate actionWithAnimation:animation]; 
[effectSprite runAction:animate]; 

我的猜测是因为动画精灵不是瓷砖地图的图层集的一部分。有没有办法将这些动画精灵动态添加到用于在该图层上绘制的某个缓存(基本上是在运行时修改拼贴集)?我以后可以从修改后的瓷砖组中删除这些精灵吗?在运行时修改tileset时是否仍然存在1024x1024限制?

在一天结束的时候,我真的希望能够在瓷砖地图上从一个瓷砖移动到另一个瓷砖,但我不知道如何以最有效的方式做到这一点。在瓦片地图上有一个效果图层,并且使用所有咒语动画(尤其是如果你不能将它们装入到1024x1024)时,看起来真的很笨重,因为组装动画时会将瓦片GID更新链接在一起,瓷砖地图。

我知道如果图层不是地图的一部分,我可以做我想要的东西 - 我可以使用屏幕坐标动画和移动精灵,但是当我知道的是平铺坐标时,将它们转换为屏幕坐标(如果这块瓷砖在屏幕上甚至是可见的)迄今为止已经回避了我的理解。你如何确定屏幕实际上可以“看到”的图块?什么是可见瓦片屏幕上的像素坐标?

我很欣赏关于如何去做这个过程的任何想法。

回答

2

你猜是什么问题的真正cuase,瓷砖地图是使用spritebatchnode创建的。 spritebatchnode就像一个更高性能的图层,你只能添加精灵,但是有一个限制,一个spritebatchnode中的所有精灵必须共享它们的纹理。所以当你试图改变一个图块来显示一个动画时,你试图从其他图块(具有默认图块纹理)的不同纹理中绘制一些东西,并导致崩溃或出现故障。我没有自己测试,但我认为如果你尝试把你所有的帧放在一个相同的纹理中,你就放置其他的瓷砖,问题就会解决。