在我的应用程序中,我有大量的不同的动画我的雪碧,并将有更多的谭在以后的版本。这是相当困难使用纹理文件将数以百计的帧,所以我想做几个tham。所以,我写了这段代码:
if (running)
{
NSArray * animations = [[physicalBody getAnimationList] objectForKey:ANIMATION_RUN];
if (!inAir)
{
currentFrame++;
if (currentFrame>=[animations count]*ANIMATION_ITERATION)
currentFrame = 0;
}
else
{
currentFrame = 2;
}
PhysicsSprite *sprite = (PhysicsSprite*)[physicalBody getSprite];
[sprite setFlipX:(moveingDirection)];
[sprite setDisplayFrame:[animations objectAtIndex:currentFrame/ANIMATION_ITERATION]];
}
else
{
NSArray * animations = [[physicalBody getAnimationList] objectForKey:ANIMATION_STAND];
currentFrame++;
if (currentFrame>=[animations count]*ANIMATION_ITERATION)
currentFrame = 0;
PhysicsSprite *sprite = (PhysicsSprite*)[physicalBody getSprite];
[sprite setFlipX:(moveingDirection)];
[sprite setDisplayFrame:[animations objectAtIndex:currentFrame/ANIMATION_ITERATION]]; //error here
}动画数组是从不同的*.png创建的,当它试图切换tham时,我得到了以下错误:
*终止应用程序由于未指定的异常'NSInternalInconsistencyException',原因:'CCSprite:当setTexture使用CCSpriteBatchNode呈现时无法工作‘
如何切换纹理文件?或者还有另一种解决办法?
发布于 2012-02-16 23:30:31
您不能更改CCSpriteBatchNode使用的纹理。
但是,您可以并且应该为将要使用的每个纹理创建一个。然后,无论何时设置显示框架,首先检查框架的纹理,并使用该纹理从当前sprite批处理节点中删除sprite,并将其添加到设置为使用与sprite框架相同的纹理的节点中。
然而,这可能会导致z排序问题。在最坏的情况下,您只需重新设计动画或不使用sprite批处理节点。
https://stackoverflow.com/questions/9305286
复制相似问题