Take the 2-minute tour ×
Game Development Stack Exchange is a question and answer site for professional and independent game developers. It's 100% free, no registration required.

I'm trying to animate a sprite in a spritesheet, the goal is to make the character walk from left to right. I subclassed CCSprite: CharacterSprite.

this is my code:

    CCSpriteFrameCache.sharedSpriteFrameCache().addSpriteFrames("WalkAnimation.plist");
    CCSpriteSheet spriteSheet = CCSpriteSheet.spriteSheet("WalkAnimation.png");
    w.addChild(spriteSheet);

    ArrayList<CCSpriteFrame> walkSprites = new ArrayList<CCSpriteFrame>();
    for(int i = 1; i<=8;++i)
    {
        walkSprites.add(CCSpriteFrameCache.sharedSpriteFrameCache().spriteFrameByName("walk"+ i +".png"));
    }
    //float randomFactor = (float)Math.random()*10;  
    CCAnimation walkAnimation = CCAnimation.animation("walk", 0.1f, walkSprites);

    Log.v("addEnemy", "Show");
    this.character = CCSprite.sprite(walkSprites.get(0));

    Log.v("addEnemy", "Don't Show");


    this.walkAction = CCRepeatForever.action(CCAnimate.action(walkAnimation, false));
    character.runAction(walkAction);        

    for(int k =0; k<amount; k++)
    {
        float randomFactor = (float)Math.random()*10;
        character.setPosition(CGPoint.ccp(-randomFactor * character.getContentSize().width/2, winSize.height / 6.0f));
        spriteSheet.addChild(character);
    }

This code is in my 2nd scene. And whenever I press on Start Game, nothing happens. But the code is executed till: character = CharacterSprite.sprite("walk1.png");

Can someone provide me of a snippet of animation using a spritesheet?

share|improve this question
    
"But the code is executed till: character = CharacterSprite.sprite("walk1.jpg");" wht does this mean? Do you mean code is not executed after that statement? –  Ayyappa Sep 29 '11 at 17:33
    
I tried to Log something after that statement and nothing happened, if I replace CharacterSprite with CCSprite nothing happens aswell. I don't know if I have subclassed it correctly that's why I tried CCSprite too. –  user729053 Sep 29 '11 at 17:39
    
I've changed my code –  user729053 Sep 29 '11 at 17:44
    
hey can you check once the log by enabling Cocos2d Debug variable??? –  Ayyappa Sep 29 '11 at 18:34
    
I don't understand what you mean –  user729053 Sep 29 '11 at 18:45

1 Answer 1

I have found the problem. the images referred from the plist are called 1.png etc while I put in walk1.png

share|improve this answer
1  
+1 for preventing Community ♦ from bumping this question again. –  eBusiness Dec 29 '11 at 19:10

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.