Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/ios/107.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Ios 设置多个精灵的动画_Ios_Cocos2d Iphone - Fatal编程技术网

Ios 设置多个精灵的动画

Ios 设置多个精灵的动画,ios,cocos2d-iphone,Ios,Cocos2d Iphone,这是创建单个精灵然后设置其动画的代码: [[CCSpriteFrameCache sharedSpriteFrameCache] addSpriteFramesWithFile:@"crowfl.plist"]; CCSpriteBatchNode *spriteSheet = [CCSpriteBatchNode batchNodeWithFile:@"crowfl.png"]; [self addChild:spriteSheet]; NSMutableArray *crowAnimFram

这是创建单个精灵然后设置其动画的代码:

[[CCSpriteFrameCache sharedSpriteFrameCache] addSpriteFramesWithFile:@"crowfl.plist"];
CCSpriteBatchNode *spriteSheet = [CCSpriteBatchNode batchNodeWithFile:@"crowfl.png"];
[self addChild:spriteSheet];
NSMutableArray *crowAnimFrames = [NSMutableArray array];
for (int i=1; i<=8; i++) {
    [crowAnimFrames addObject:[[CCSpriteFrameCache sharedSpriteFrameCache] spriteFrameByName:[NSString stringWithFormat:@"crow%d.png", i]]];
}
CCAnimation *crowAnim = [CCAnimation animationWithSpriteFrames:crowAnimFrames delay:0.1f];
_crow = [CCSprite spriteWithSpriteFrameName:@"crow1.png"];
_crow.position = ccp(windowSize.width + _crow.contentSize.width/2, _crowFlightHeight);
id crowAction = [CCRepeatForever actionWithAction:[CCAnimate actionWithAnimation:crowAnim]];
[_crow runAction:crowAction];
[spriteSheet addChild:_crow];
...
id crowMoveAction = [CCSequence actions:
                     [CCMoveTo actionWithDuration:5.0 position:ccp(_flipCrow ?   (windowSize.width + _crow.contentSize.width/2) : (-_crow.contentSize.width/2), _crowFlightHeight)],
                     crowMoveComplete,
                     nil];
[_crow runAction:crowMoveAction];
[[CCSpriteFrameCache sharedSpriteFrameCache]addSpriteFramesWithFile:@“crowfl.plist”];
CCSpriteBatchNode*spriteSheet=[CCSpriteBatchNode batchNodeWithFile:@“crowfl.png”];
[自添加子项:精灵表];
NSMutableArray*crowAnimFrames=[NSMutableArray];

对于(int i=1;i在CCAnimationCache中缓存动画,这样可以减少一次又一次加载的延迟:

CCAnimation* crowAnim = nil;
crowAnim = [[CCAnimationCache sharedAnimationCache]  animationByName:@"crowAnim"];

if(!crowAnim)
{
    [[CCSpriteFrameCache sharedSpriteFrameCache] addSpriteFramesWithFile:@"crowfl.plist"];
    CCSpriteBatchNode *spriteSheet = [CCSpriteBatchNode batchNodeWithFile:@"crowfl.png"];
    [self addChild:spriteSheet];
    NSMutableArray *crowAnimFrames = [NSMutableArray array];
    for (int i=1; i<=8; i++) {
        [crowAnimFrames addObject:[[CCSpriteFrameCache sharedSpriteFrameCache] spriteFrameByName:[NSString stringWithFormat:@"crow%d.png", i]]];
    }

    crowAnim = [CCAnimation animationWithSpriteFrames:crowAnimFrames delay:0.1f];

    [[CCAnimationCache sharedAnimationCache] addAnimation:crowAnim name:@"crowAnim"];

}

_crow = [CCSprite spriteWithSpriteFrameName:@"crow1.png"];
_crow.position = ccp(windowSize.width + _crow.contentSize.width/2, _crowFlightHeight);
id crowAction = [CCRepeatForever actionWithAction:[CCAnimate actionWithAnimation:crowAnim]];
[_crow runAction:crowAction];
[spriteSheet addChild:_crow];
...
id crowMoveAction = [CCSequence actions:
                     [CCMoveTo actionWithDuration:5.0 position:ccp(_flipCrow ?   (windowSize.width + _crow.contentSize.width/2) : (-_crow.contentSize.width/2), _crowFlightHeight)],
                     crowMoveComplete,
                     nil];
[_crow runAction:crowMoveAction];
CCAnimation*crowAnim=nil;
crowAnim=[[CCAnimationCache sharedAnimationCache]animationByName:@“crowAnim”];
如果(!crowAnim)
{
[[CCSpriteFrameCache sharedSpriteFrameCache]addSpriteFramesWithFile:@“crowfl.plist”];
CCSpriteBatchNode*spriteSheet=[CCSpriteBatchNode batchNodeWithFile:@“crowfl.png”];
[自添加子项:精灵表];
NSMutableArray*crowAnimFrames=[NSMutableArray];

对于(int i=1;i实际上我可以使用
crowAnim
作为类成员并创建一次,但是这个示例帮助我确定创建一次需要动画。thx