• Animation in Cocos2diphone


    Animation in Cocos2d-iphone v2.0.0

    What you need

    1.a png file -- default.png
    2.a plist file -- default.plist (anim01.png -- anim10.png)
        (you can get png file and plist file from: )
             Zwoptex http://zwoptexapp.com          TexturePacker http://texturepacker.com

    Cocos2d-iphone code

    1.load plist file to CCSpriteFrameCache

    [[CCSpriteFrameCache sharedSpriteFrameCache] addSpriteFramesWithFile: @"default.plist"];

    2.load png file to CCSpriteBatchNode

    CCSpriteBatchNode *spriteBatchNode = [CCSpriteBatchNode batchNodeWithFile: @"default.png"];

    3.add batch node to layer

    [self addChild: spriteBatchNode];

    4.create a sprite from frame cache

    animSprite = [CCSprite spriteWithSpriteFrameName: @"anim01.png"];

    5.add sprite to layer

    [self addChild: animSprite];

    6.create animation

    CCAnimation* animation = [CCAnimation animation];

    7.add frame from frame cache to animation

    [animation addSpriteFrame: [[CCSpriteFrameCache sharedSpriteFrameCache] spriteFrameByName: @"anim02.png"]];
    [animation addSpriteFrame: [[CCSpriteFrameCache sharedSpriteFrameCache] spriteFrameByName: @"anim03.png"]];
    [animation addSpriteFrame: [[CCSpriteFrameCache sharedSpriteFrameCache] spriteFrameByName: @"anim04.png"]];
    [animation addSpriteFrame: [[CCSpriteFrameCache sharedSpriteFrameCache] spriteFrameByName: @"anim05.png"]];
    [animation addSpriteFrame: [[CCSpriteFrameCache sharedSpriteFrameCache] spriteFrameByName: @"anim06.png"]];
    [animation addSpriteFrame: [[CCSpriteFrameCache sharedSpriteFrameCache] spriteFrameByName: @"anim07.png"]];
    [animation addSpriteFrame: [[CCSpriteFrameCache sharedSpriteFrameCache] spriteFrameByName: @"anim08.png"]];
    [animation addSpriteFrame: [[CCSpriteFrameCache sharedSpriteFrameCache] spriteFrameByName: @"anim09.png"]];
    [animation addSpriteFrame: [[CCSpriteFrameCache sharedSpriteFrameCache] spriteFrameByName: @"anim10.png"]];

    8.set some properties of animation

    [animation setDelayPerUnit: 0.02f];
    [animation setRestoreOriginalFrame: YES];
    [animation setLoops: 100];

    9.create animation action

    id animationaction = [CCAnimate actionWithAnimation: animation];

    10.run animation action

    [animSprite runAction: animationaction];

  • 相关阅读:
    spring ContextUtils
    mysql top slow sql my.cnf配置
    _mysql_exceptions.OperationalError: (2006, 'MySQL server has gone away')
    linux Must my pidfile be located in /var/run? Stack Overflow
    zc.lockfile 1.0.0
    python Limit amount of RAM to a process (Linux) Server Fault
    使用 Nginx 提升网站访问速度
    bitnami mysql my.cnf配置
    Django pickling
    一个查找rpm包的站
  • 原文地址:https://www.cnblogs.com/ketmales/p/2842166.html
Copyright © 2020-2023  润新知