+ [CCSprite spriteWithSpriteFrameName:]中的断言失败?

时间:2013-04-01 02:31:38

标签: xcode cocos2d-iphone sprite ccsprite cgsize

由于某种原因,我在+ [CCSprite spriteWithSpriteFrameName:] 中遇到断言失败。

我基本上试图“updatePinkBerries”或换句话说,创建更多精灵'浆果'以添加到屏幕上。他们是我游戏中的“敌人”。

这是我的代码:

- (id) init
{
    if((self = [super init]))
    {

        CCLOG(@"%@ init", NSStringFromClass([self class]));

        self.touchEnabled = YES;

        [self scheduleUpdate];
    }
    return self;
}

-(void)updatePinkBerries:(ccTime)dt
{
    CGSize winSize = [CCDirector sharedDirector].winSize;

    double curTime = CACurrentMediaTime();

    if (curTime > _nextPinkBerrySpawn)
    {
        // Figure out the next time to spawn an asteroid
        float randSecs = randomValueBetween(0.20, 1.0); _nextPinkBerrySpawn = randSecs + curTime;

        // Figure out a random Y value to spawn at
        float randY = randomValueBetween(0.0, winSize.height);

        // Figure out a random amount of time to move from right to left
        float randDuration = randomValueBetween(2.0, 10.0);

        // Create a new asteroid sprite
        CCSprite *pinkBerry = [CCSprite spriteWithSpriteFrameName:@"ship.png"]; [_batchNode addChild:pinkBerry];

        // Set its position to be offscreen to the right
        pinkBerry.position = ccp(winSize.width + pinkBerry.contentSize.width/2, randY);

        // Move it offscreen to the left, and when it's done, call removeNode
        [pinkBerry runAction:
         [CCSequence actions:
          [CCMoveBy actionWithDuration:randDuration position:ccp(-winSize.width- pinkBerry.contentSize.width, 0)],
          [CCCallFuncN actionWithTarget:self selector:@selector(removeNode:)], nil]];
    }
}
  

编辑:完整的评估日志:

     

2013-03-31 19:39:09.225 Berry Muncher-iOS [19550:c07] - [CCFileUtils   fullPathForFilename:resolutionType:]:cocos2d:警告:文件没有   发现:Sprites.plist 2013-03-31 19:39:09.225 Berry   Muncher-iOS [19550:c07] cocos2d:CCSpriteFrameCache:尝试使用文件   'Sprites.png'作为质地2013-03-31 19:39:09.425 Berry   Muncher-iOS [19550:c07] cocos2d:CCSpriteFrameCache:Frame'ship.png'   未找到2013-03-31 19:39:09.426 Berry Muncher-iOS [19550:c07] ***   + [CCSprite spriteWithSpriteFrameName:]中的断言失败,   /Users/Sur​​aya/Desktop/Kobold2D/Kobold2D-2.1.0/的 Kobold2D /libs/cocos2d-iphone/cocos2d/CCSprite.m:105

编辑:我的plist的截图

enter image description here

1 个答案:

答案 0 :(得分:1)

我从Ray Wanderlich教程中认识到了这一点。因为他有不同的艺术作品,你应该创建自己的CCSpriteBatchNode和随附的plist文件,这样他的项目中的项目名称就不会与你的项目混淆。