在Cocos2d iOS中有大量精灵的动画?

时间:2013-07-17 12:07:13

标签: ios cocos2d-iphone sprite-sheet zwoptex

我必须动画(跳舞) 角色(家伙)约6-7秒,即 500-600帧。之前我已经使用 zwoptex 创建了spritesheets,然后使用 CCSpriteFrameCache&&在The Great Ray Wenderlich的帮助下,CCSpriteBatchNode 。但在这种情况下帧数量很大我不确定iOS设备是否能够支持它。使用小开销尽可能为所有这些帧设置动画的最佳流程是什么。动画时我可以更改 fps 吗?任何想法的人?

1 个答案:

答案 0 :(得分:0)

这里我把代码用于添加动画图像而不使用 TexturePacker

CCSprite *dog = [CCSprite spriteWithFile:@"dog1.gif"];
        dog.position = ccp(winSize.width/2, winSize.height/2);
        [self addChild:dog z:2];

        NSMutableArray *animFrames = [NSMutableArray array];
        for( int i=1;i<=5;i++)
        {
            NSString* file = [NSString stringWithFormat:@"dog%d.gif", i];
            CCTexture2D* texture = [[CCTextureCache sharedTextureCache] addImage:file];
            CGSize texSize = texture.contentSize;
            CGRect texRect = CGRectMake(0, 0, texSize.width, texSize.height);
            CCSpriteFrame* frame = [CCSpriteFrame frameWithTexture:texture rect:texRect];
            [animFrames addObject:frame];
        }
        CCAnimation * animation = [CCAnimation animationWithSpriteFrames:animFrames];
        animation.delayPerUnit = 0.07f;
        animation.restoreOriginalFrame = YES;

        CCAnimate *animAction  = [CCRepeatForever actionWithAction:[CCAnimate actionWithAnimation:animation]];
        [dog runAction:animAction];

尝试使用此代码,我不确定在您的情况下是否有帮助: