开发者

Assertion failure in this line

CCSprite *ni = [CCSprite spriteWithFile:@"blue_animation.png"];
ni.position = ccp(5,66);

[[CCSpriteFrameCache sharedSpriteFrameCache] addSpriteFramesWithFile:
    @"blue_ani.plist"];

CCSpriteBatchNode *spriteSheet = [CCSpriteBatchNode 
                                  batchNodeWithFile:@"blue_ani.png"];
[self addChild:spriteSheet];
NSMutableArray *walkAnimFrames = [NSMutableArray array];
for(int i = 1; i <= 3; ++i) {
    [walkAnimFrames addObject:
        [[CCSpriteFrameCache sharedSpriteFrameCache] spriteFrameByName:
        [NSString stringWithFormat:@"baloon-bl_%d.png", i]]];
}
CCAnimation *walkAnim = [CCAnimation 
                         animationWithFrames:walkAnimFrames delay:0.1f];

CCSprite *blue_action_1 = [CCSprite spriteWithSpriteFrameName:@"blue_ani.png"];        
CGSize winSize = [CCDirector sharedDirector].winSize;

blue_action_1.position = ccp(winSize.width/2, winSize.height/2);
self.blue_action_motion = [CCRepeatForever actionWithAction:
                          [CCAnimate actionWithAnimation:walkAnim restoreOriginalFrame:NO]];
[blue_action_1 runActi开发者_运维百科on:blue_action_motion];
[spriteSheet addChild:blue_action_1]; 

Assertion failure in -[CCSprite initWithSpriteFrame:] in cocso2d

how can I fix it.


Try replacing this line:

CCSprite *blue_action_1 = [CCSprite spriteWithSpriteFrameName:@"blue_ani.png"];

With this line:

CCSprite *blue_action_1 = [CCSprite spriteWithSpriteFrameName:@"baloon-bl_1.png"];

Basically your "blue_ani.png" is a spritesheet that contains multiple sprites so you cannot use the whole spritesheet as your sprite. So you need to initialize your blue_action_1 sprite using one of the sprites by providing a valid frame name ("baloon-bl_1.png", "baloon-bl_2.png" or "baloon-bl_3.png" if I deduced correctly from your code).


this is my code

CCSprite *ni = [CCSprite spriteWithFile:@"blue_animation.png"];
            ni.position = ccp(5,66);

            [[CCSpriteFrameCache sharedSpriteFrameCache] addSpriteFramesWithFile:
             @"blue_ani.plist"];

            CCSpriteBatchNode *spriteSheet = [CCSpriteBatchNode 
                                              batchNodeWithFile:@"blue_ani.png"];
            [self addChild:spriteSheet];
            NSMutableArray *walkAnimFrames = [NSMutableArray array];
            for(int i = 1; i <= 3; ++i) {
                [walkAnimFrames addObject:
                 [[CCSpriteFrameCache sharedSpriteFrameCache] spriteFrameByName:
                  [NSString stringWithFormat:@"baloon-bl_%d.png", i]]];
            }
            CCAnimation *walkAnim = [CCAnimation 
                                     animationWithFrames:walkAnimFrames delay:0.1f];

            CCSprite *blue_action_1 = [CCSprite spriteWithSpriteFrameName:@"blue_ani.png"];        
            CGSize winSize = [CCDirector sharedDirector].winSize;

            blue_action_1.position = ccp(winSize.width/2, winSize.height/2);
            self.blue_action_motion = [CCRepeatForever actionWithAction:
                               [CCAnimate actionWithAnimation:walkAnim restoreOriginalFrame:NO]];
            [blue_action_1 runAction:blue_action_motion];
            [spriteSheet addChild:blue_action_1];


did you add your CCSprite* ni as child?

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜