在我的应用程序中,我的精灵有很多不同的动画,在以后的版本中会有更多的动画。使用纹理文件会相当困难,数百帧,所以我想做几个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'
渲染精灵时不起作用
如何切换纹理文件?或者可能还有另一种解决方案?
答案 0 :(得分:0)
您无法更改CCSpriteBatchNode使用的纹理。
但是,您可以而且应该为 要使用的每个纹理创建一个CCSpriteBatchNode。然后,每当你设置一个显示框时,首先检查框架的纹理并使用它来从当前的sprite批处理节点中删除sprite,并将其添加到设置为使用与sprite框架相同的纹理的那个。
然而,这可能导致z订购问题。在最糟糕的情况下,您只需重新设计动画或不使用精灵批处理节点。