我刚开始学习cocos2d-iphone 2.x。
当尝试制作 CCSprite 的动画时,会出现错误。
我的代码如下:
CCTexture2D *texture=[[CCTextureCache sharedTextureCache] addImage:@"dragon.png"];
CCSpriteBatchNode *spriteSheet=[CCSpriteBatchNode batchNodeWithTexture:texture];
[self addChild:spriteSheet];
NSMutableArray *animFrames=[[NSMutableArray alloc]init];
for (int i=1; i<8; i++) {
[animFrames addObject:[CCSprite spriteWithTexture:spriteSheet.texture rect:CGRectMake(i*75, 0, 75, 70)]];
}
CCAnimation *flyAnim=[CCAnimation animationWithSpriteFrames:animFrames delay:0.1f];
CGSize winSize=[CCDirector sharedDirector].winSize;
CCSpriteFrame *frame3=[CCSpriteFrame frameWithTexture:texture rectInPixels:CGRectMake(0, 0, 75, 70) rotated:NO offset:CGPointZero originalSize:CGSizeMake(75, 70)];
self.dragon=[CCSprite spriteWithSpriteFrame:frame3];
_dragon.position=ccp(winSize.width/2,winSize.height/2);
self.flyAction=[CCRepeatForever actionWithAction:[CCAnimate actionWithAnimation:flyAnim]];
[_dragon runAction:_flyAction];
[spriteSheet addChild:_dragon];
有什么不对的吗?