2011年3月28日 星期一

CCSpriteBatchNode Updated to CCSpriteSheet

CCSpriteBatchNode *waterDropBatchNode = [CCSpriteBatchNode batchNodeWithFile:@"waterDropSeq.png"];
        [self addChild:waterDropBatchNode z:4 tag:kTagSpriteBatchNode];
        
        waterDropSprite = [CCSprite spriteWithTexture:waterDropBatchNode.texture rect:CGRectMake(0, 0, 120, 120)];
        [waterDropBatchNode addChild:waterDropSprite];
        
        //CCSpriteFrameCache *cache = [CCSpriteFrameCache sharedSpriteFrameCache];
        
        NSMutableArray *animFrames = [NSMutableArray array];
        
        int frameCount = 0;
        for (int y = 0; y < 3; y++) {
            for (int x = 0; x < 4; x++) {
                CCSpriteFrame *frame = [CCSpriteFrame frameWithTexture:waterDropBatchNode.texture rect:CGRectMake(x*120,y*120,120,120)];
                [animFrames addObject:frame];
                
                frameCount++;
                
                if (frameCount == 11)
                    break;
            }
        }
        
        
CCAnimation *animation = [CCAnimation animationWithFrames:animFrames];
[waterDropSprite runAction:[CCRepeatForever actionWithAction: [CCAnimate actionWithDuration:1.0f animation:animation restoreOriginalFrame:NO] ]];

        [waterDropSprite setPosition:ccp(160, 240)];

沒有留言:

張貼留言