• [cocos2d]create annimation sprite controled by ourself


    1. create a batchnode like with the picture created by Textures Paker

    CCSpriteBatchNode *spriteSheet =[CCSpriteBatchNode batchNodeWithFile:@"AnimBear.jpg"];

    2. cache sprite frames with plist (also created together with above)

    [[CCSpriteFrameCache sharedSpriteFrameCache] addSpriteFramesWithFile:@"AnimBear.plist"]

    3. create a array with frame like:

    NSMutableArray*walkAnimFrames =[NSMutableArray array];

    for(int i =1; i <=8; ++i){[walkAnimFrames addObject:[[CCSpriteFrameCache sharedSpriteFrameCache] spriteFrameByName:[NSString stringWithFormat:@"bear%d.jpg", i]]];

    }

    4. Create an animation:

    CCAnimation *walkAnim =[CCAnimation 

        animationWithFrames:walkAnimFrames delay:0.1f];

    (till now, you can use this animation to play it by action, but this is not the way I want. I want to control this annimation by myself)

    *here comes the better part:

    5. Add CCAnimation to CCAnimationCache with addAnimation with name

    6. create a sprite with first frame [CCSprite spriteWithSpriteFrameName:@"bear1.jpg"]

    7. use this below msg to update the frame as will

    - (void) setDisplayFrameWithAnimationName:

     

    (NSString *) 

    animationName

    index:

     

    (int) 

    frameIndex 

     

  • 相关阅读:
    假期小作业1
    Python_day4
    Python_day3
    Python_day2
    12/06
    12/05
    python系统学习:第三周之简单的三级菜单
    python系统学习:第二周之字典应用
    python系统学习:第二周之字符串函数练习
    python系统学习:第二周之购物车功能
  • 原文地址:https://www.cnblogs.com/dqshll/p/2644349.html
Copyright © 2020-2023  润新知