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];

  • 相关阅读:
    二部图(二分图判定--dfs)
    chd校内选拔赛题目+题解
    敌兵布阵 线段树单点更新
    Employment Planning DP
    Tickets 基础DP
    Super Jumping! Jumping! Jumping! 基础DP
    【高精度加法】
    【最短路径之dijkstra(迪杰斯特拉)算法】
    各类最短路算法基本模板-C++
    【最小生成树之Prim算法】-C++
  • 原文地址:https://www.cnblogs.com/ketmales/p/2842166.html
Copyright © 2011-2022 走看看