Search code examples
androidcocos2d-android

Android Cocos 2d


i am new to android and cocos2d for android .. i found the api at an unknown site

first question is cocos2d officially available for android second i am having trouble with displaying animations please help

i have images name "download (1).gif" too "download (8).gif" in the assets folder and here is my code

the app crashes right after opening

 public void addAnimation() {

     CCSprite addboxPuzzleOpen = CCSprite.sprite("download (1).gif");           
     addboxPuzzleOpen.setPosition(100,100);      
     addChild(addboxPuzzleOpen);

     CCAnimation OpenPuzzleAnim = CCAnimation.animation("", 0.2f);

     for (int i = 1; i < 8; i++) {            
             OpenPuzzleAnim.addFrame(CCSpriteFrameCache.sharedSpriteFrameCache().spriteFrameByName("download ("+i+").gif"));                 
        }
        CCAction OpenPuzzleAction = CCAnimate.action(2, OpenPuzzleAnim, true);
         addboxPuzzleOpen.runAction(OpenPuzzleAction);

     //}
 }

Solution

  • just change your image name like : download_00.gif to download_08.gif

    and

    replace this line :

    OpenPuzzleAnim.addFrame(CCSpriteFrameCache.sharedSpriteFrameCache().spriteFrameByName("download ("+i+").gif")); to ...

    OpenPuzzleAnim.addFrame(String.format("download_%02d.png", i));

    If its not work fine then change the format of the gif to png or jpg for the anomation effect ... njoy