How to create Animation using Cocos2d in java?

1.7k Views Asked by At

I only started Cocos2d. Can someone explain plz how to create animation with several frames where all frames are different images or how to use and create on image and *.plist file?

2

There are 2 best solutions below

3
On BEST ANSWER

you need to create an object of CCAnimation, add all the image frames in it, then create an object of CCAnimate add the CCAnimation object in it. then use the CCAnimate object in runAction of your main object.

0
On

i use this code for my animation for diamonds so try this out this is the way to do animation in cocos2d you...hope it will help full for you...

  public void openScrPpr(float duration, CCSprite scrPprRoller) {

            CCAnimation scrPprAnim = CCAnimation.animation("", 2 / 20f);

            for (int i = 20; i > 1; i--) {

                if (i >= 10 && i <= 20) {
                    scrPprAnim.addFrame(CCSpriteFrameCache.sharedSpriteFrameCache().spriteFrameByName("paperrol." + i + ".png"));
                } else {
                    scrPprAnim.addFrame(CCSpriteFrameCache.sharedSpriteFrameCache().spriteFrameByName("paperrol.0" + i + ".png"));
                }
            }

            CCAction scrPprAction = CCAnimate.action(duration, scrPprAnim, false);
            scrPprRoller.runAction(scrPprAction);