这是我收到的错误:
* 由于未捕获的异常'NSInternalInconsistencyException'而终止应用程序,原因:'当使用CCSpriteBatchNode呈现精灵时,'CCSprite:setTexture不起作用'
当我试图通过动画时。
这是我创作的动画:
_tokenAnimation = [[CCAnimation alloc] init];
int frameCount = 12;
for (int i = 1; i <= frameCount; i++)
{
CCSpriteFrame *frame = [[CCSpriteFrameCache sharedSpriteFrameCache] spriteFrameByName:[NSString stringWithFormat:@"Token Ball 000%d.png", i]];
[_tokenAnimation addFrame:frame delay:0.1];
}
这是我调用动画 - 之前没见过这个?
GameObject *creditPickup = [_creditPickups nextSprite];
creditPickup.position = ccp(_creditPosition.x, _creditPosition.y);
[creditPickup revive];
[creditPickup runAction:[CCRepeatForever actionWithAction:[CCAnimate actionWithAnimation:_tokenAnimation restoreOriginalFrame:NO]]];
[creditPickup runAction: [CCSequence actions:
[CCMoveBy actionWithDuration:5.0 position:ccp(-_winSize.width*1.5, 0)],
[CCCallFuncN actionWithTarget:self selector:@selector(invisNode:)], nil]];
我听说有关CCSpriteBatchNode不好的事情?如果是这样,我怎么能改变我的spritesheet的读数?
还有别的我做错了吗?
答案 0 :(得分:2)
你的问题就在那里:
CCSprite:使用a渲染精灵时,setTexture不起作用 CCSpriteBatchNode'
这意味着作为CCSpriteBatchNode的子节点添加的CCSprite都不能运行setTexture方法。原因是它们都必须使用与其父CCSpriteBatchNode相同的纹理。所以cocos2d在精灵批处理的sprite上禁用该方法。
在你的情况下,最有可能的是,动画的至少一个精灵帧不在其子精灵播放该动画的CCSpriteBatchNode使用的纹理中。
I hear something about CCSpriteBatchNode's being bad?
是的,这很糟糕。太糟糕了,它确实是月球漫步。 :)
答案 1 :(得分:0)
试试这个:
CCAnimation* animation;
NSMutableArray *animFrames = [NSMutableArray array];
CCSpriteFrameCache *cache = [CCSpriteFrameCache sharedSpriteFrameCache];
for(int i=0;i<=12;i++)
{
CCSpriteFrame *frame = [[CCSpriteFrameCache sharedSpriteFrameCache] spriteFrameByName:[NSString stringWithFormat:@"Token Ball 000%d.png", i]]
[animFrames addObject:frame];
}
animation = [CCAnimation animationWithSpriteFrames:animFrames];
animation.delayPerUnit = 0.1f;
animation.restoreOriginalFrame = NO;
CCAnimate *AnimAction = [CCAnimate actionWithAnimation:animation];
CCRepeatForever *anim = [CCRepeatForever actionWithAction:AnimAction];
[creditPickup runAction:anim];