0

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

     //}
 }
Ifti
  • 77
  • 11
  • Which line is crashing? Could you share a log? – ssantos Apr 10 '13 at 19:28
  • the only error i found is :04-11 04:20:20.497: D/CCSpriteFrameCache(843): Frame not found: Projectile (1).png" ... but my pngs are in the assets folder .... and havent made any plists – Ifti Apr 11 '13 at 04:22
  • [this][1] might be helpful to you !! [1]: http://stackoverflow.com/questions/10959337/cocos-vs-andengine-for-android/15900159#15900159 – user2416728 Jun 05 '13 at 05:25

2 Answers2

0

Cocos2D is only available for iOS. On Android you must use Cocos2d-x which is a c++ port of the engine. The classes and methods are very similar to the Objective-c ones. To call java methods from there you can use JNI (example here : http://www.useatyourownrisk.net/calling-java-methods-from-c-with-cocos2d-x/). If you want to know how to configure Eclipse to work with Cocos2d-x for Android, there's one on Ray Wenderlich's website : http://www.raywenderlich.com/11283/cocos2d-x-for-ios-and-android-getting-started

dqms
  • 303
  • 1
  • 10
0

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

Akarsh M
  • 1,629
  • 2
  • 24
  • 47
  • 1
    gif its not give the animation in the cocos2d android .. when i tried that time application was crashed .. this one is the good option and better explain in the cocos2d-android example series .... –  Apr 14 '13 at 18:11