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

  • 相关阅读:
    BZOJ 3514 Codechef MARCH14 GERALD07加强版
    WT
    Codeforces 348
    POI 2010
    Codeforces 336
    MVC实例及用三层架构实现对学生信息的增删改查
    欠拟合和过拟合
    线性回归案例
    梯度下降法介绍
    线性回归的损失函数和梯度下降
  • 原文地址:https://www.cnblogs.com/ketmales/p/2842166.html
Copyright © 2011-2022 走看看