zoukankan      html  css  js  c++  java
  • [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 

     

  • 相关阅读:
    复习时间
    核反应堆
    假期编程
    剪花布条
    Atcoder Regular Contest 072 C Alice in linear land(思维题)
    xss攻击入门
    转发 DDoS攻防战 (一) : 概述
    XSS跨站脚本攻击
    sql注入
    关于阿里云图片识别接口的demo
  • 原文地址:https://www.cnblogs.com/dqshll/p/2644349.html
Copyright © 2011-2022 走看看