2013-02-11 2 views
0

Im пытается сделать игру в cocos2d. У меня есть версия, прежде чем они лишили ccspritesheet и все эти вещи. Я пытаюсь взорвать корабль. сво ccsprite, и я запускаю этот код в - (ID) инициализацииПрограмма анимационных сбоев COCOS2D

 CCSpriteSheet * sheet = [CCSpriteSheet spriteSheetWithFile:@"Explode.png"]; 

    [self addChild:sheet]; 

    NSMutableArray * explosionFrames = [NSMutableArray array]; 

    int spriteWidth = 256; 

    for (int i = 0; i <= 6; i++) { 
     [explosionFrames addObject:[CCSprite spriteWithSpriteSheet:sheet rect:CGRectMake(i*spriteWidth, 0, spriteWidth, 100)]]; 
    } 

    CCAnimation * animation = [CCAnimation animationWithName:@"explode" delay:0.1f frames:explosionFrames]; 

    CCAnimate * explosion = [CCAnimate actionWithDuration:.5f animation:animation restoreOriginalFrame:NO]; 

    [self runAction:explosion]; 

, когда я запускаю программу она просто падает сразу говоря

-[CCSprite rect]: unrecognized selector sent to instance 0x54484f0 

в консоли.

Я понятия не имею, что происходит. это мой первый раз, пытаясь одушевиться в кокосах, и я, вероятно, идиот. любая помощь почти такая же потрясающая, как и. Благодаря!

Я не могу загрузить лист спрайтов im, потому что я новичок, и это не позволит мне, и это имеет смысл. но сво 1792 × 100 PNG

+0

Билеты на поезд CLUE составляют $ 10. Попасть на борт! –

ответ

0

Устаревшей CCSpriteSheet был заменен CCSpriteBatchNode. Но так или иначе, чтобы создать спрайт из rect спрайта, вы должны называть [CCSprite spriteWithTexture: sheet.texture rect: yourRect], где sheet - ваш CCSpriteBatchNode.

Следующий код должен работать на cocos2d 2.x. Для хорошего учебника по анимации с использованием spritesheets в cocos2d, проверьте: http://www.raywenderlich.com/1271/how-to-use-animations-and-sprite-sheets-in-cocos2d

// Create a batchnode from your spritesheet file 
    CCSpriteBatchNode *sheet = [CCSpriteBatchNode batchNodeWithFile:@"Explode.png"]; 
    [self addChild:sheet]; 

    int spriteWidth = 256; 

    // Create the sprite starting with the first frame. 
    CCSprite *sprite = [CCSprite spriteWithTexture:sheet.texture rect:CGRectMake(0, 0, spriteWidth, 100)]; 
    CGSize winSize = [[CCDirector sharedDirector] winSize]; 
    sprite.position = ccp(winSize.width/2, winSize.height/2); 

    // Create the array the holds the animation frames 
    NSMutableArray * explosionFrames = [NSMutableArray array]; 
    for (int i = 0; i <= 6; i++) 
    { 
     [explosionFrames addObject:[CCSpriteFrame frameWithTexture:sheet.texture rect:CGRectMake(i*spriteWidth, 0, spriteWidth, 100)]]; 
    } 

    // Create the animation from those frames. 
    CCAnimation * animation =[CCAnimation animationWithSpriteFrames:explosionFrames delay:.2f]; 
    CCAnimate * explosion = [CCAnimate actionWithAnimation:animation]; 

    // Start running the animation 
    [sprite runAction:explosion]; 

    // Add the explosion as child of spritesheet 
    [sheet addChild:sprite]; 
+0

Не могли бы вы рассказать мне, что не так с моим кодом? Я действительно смущен. Спасибо за ответ! –

Смежные вопросы