CCSprite: setTexture doesn't work when the sprite is rendered using a CCSpriteSheet

Posted by srikanth rongali on Stack Overflow See other posts from Stack Overflow or by srikanth rongali
Published on 2010-05-22T06:28:39Z Indexed on 2010/05/22 6:30 UTC
Read the original article Hit count: 563

Filed under:
|

My code is in cocos2d.

I am getting this error in my code. To get the fast animation I used CCSpriteSheet

        CCSpriteSheet *danceSheet = [CCSpriteSheet spriteSheetWithFile:@"new1.png"];
        [self addChild:danceSheet];

        CCSprite *danceSprite = [CCSprite spriteWithTexture:danceSheet.texture rect:CGRectMake(0, 0, 119, 320)];
        [danceSheet addChild:danceSprite];

        danceSprite.position = ccp(danceSprite.contentSize.width/2,danceSprite.contentSize.height/2);


        CCAnimation *danceAnimation = [CCAnimation animationWithName:@"dance" delay:0.1f];

        int frameCount = 0;

        for (int x = 0; x < 13; x++) 
        {
            // create an animation frame
            CCSpriteFrame *frame = [CCSpriteFrame frameWithTexture:danceSheet.texture rect:CGRectMake(x*119,0,119,320) offset:ccp(0,0)];

            [danceAnimation addFrame:frame];
            frameCount++;
            NSLog(@"frameCount value: %d", frameCount);
            if (frameCount == 13)
                break;
        }

        CCAnimate *danceAction = [CCAnimate actionWithAnimation:danceAnimation restoreOriginalFrame:NO ];

        [danceSprite runAction:danceAction];  

But when I touched the screen it is giving the error

CCSprite: setTexture doesn't work when the sprite is rendered using a CCSpriteSheet         

© Stack Overflow or respective owner

Related posts about cocoa-touch

Related posts about cocos2d-iphone