2012-05-15 4 views
0

저는 cocos2d에 더 최신이며 내 데모 게임을 준비하고 있습니다. 나는 왼쪽에서 오른쪽으로 움직이는 새 이미지와 같은 단 하나의 이미지를 사용하여 스프 라이트를 오른쪽에서 왼쪽으로 움직입니다. 하지만 나는 다양한 이미지를 통해 그 스프라이트를 움직여서 날으는 새처럼 보일 수 있습니다. 나는 그것을 성취 할 방법을 모른다.Animate CCSprite

여기 내 코드를 :

CCSprite *target = [CCSprite spriteWithFile:@"Target.png" rect:CGRectMake(0, 0, 27, 40)] 
id actionMove = [CCMoveTo actionWithDuration:actualDuration position:ccp(-target.contentSize.width/2, actualY)]; 
    id actionMoveDone = [CCCallFuncN actionWithTarget:self selector:@selector(spriteMoveFinished:)]; 
    [target runAction:[CCSequence actions:actionMove, actionMoveDone, nil]]; 

사전에 답변

감사합니다 감사합니다!

답변

3

특정 스프라이트 애니메이션하기 리소스에 스프라이트 시트가 있어야합니다. 평소 사용하는 Texture Packer 또는 Zwoptex 도구에서 스프라이트 시트를 만들 수 있습니다.

다음 당신은 내가이 애니메이션을 만들어 주셔서 도움이 될 생각 아래 코드

CCSpriteBatchNode *sheet = [CCSpriteBatchNode batchNodeWithFile:@"drawing1-i3.png"]; // Png File Name 
    [[CCSpriteFrameCache sharedSpriteFrameCache] addSpriteFramesWithFile:@"drawing1-i3.plist"]; // Plist File Name 
    [self addChild:sheet]; 

     //Generating the Animation 
    NSMutableArray *arr_anim =[NSMutableArray array]; 
    for(int i=1; i<30; i++) // i< number of frames in the plist File Name 
    { 
     NSString *str_fileNm = [NSString stringWithFormat:@"drawing1%d.png",i]; 
     CCSpriteFrame *frame = [[CCSpriteFrameCache sharedSpriteFrameCache]spriteFrameByName:str_fileNm]; 
     [arr_anim addObject:frame]; 
    } 

    CCSprite *startAnim = [CCSprite spriteWithSpriteFrameName:@"drawing11.png"]; 
    [startAnim setPosition:ccp(150,150)]; 
    [self addChild:startAnim]; 

    //Starting the Animation 
    CCAnimation *animation = [CCAnimation animationWithFrames:arr_anim delay:0.15f]; 
    // id action =[CCRepeatForever actionWithAction:[CCAnimate actionWithAnimation:animation restoreOriginalFrame:YES]]; 
    id action =[CCAnimate actionWithAnimation:animation restoreOriginalFrame:NO]; 
    [startAnim runAction:action]; 

을 구현할 수 있습니다.

+0

스프라이트 시트는 애니메이션을위한 요구 사항이 아닙니다. – johnbakers

+0

'startAnim' 스프라이트는 배치 노드의 자식으로 추가되어야합니다. 이는 단일 OpenGL 호출 또는 "배치 그리기"만을 사용합니다. – nrj