0

我使用CCSpriteBatchNode,但我遇到了一些异常错误。这是我的代码:

//Use CCSpriteBatchNode.....!!!

    CCSpriteBatchNode *singleGameSpriteBatchNode;       

    //if < 16 , create dice

    unsigned int createDiceNumber = 4 - (maxDiceNumber%4) ;
    for (int i = 0; i<createDiceNumber; i++) {
        CCLOG(@"Total dice number = %d" , createDiceNumber);
        int randomDiceNumber = arc4random()%17;
        [[CCSpriteFrameCache sharedSpriteFrameCache] addSpriteFramesWithFile:@"singleGameImage.plist"];
        singleGameSpriteBatchNode = [CCSpriteBatchNode batchNodeWithFile:@"singleGameImage.png"];
        Dice *tempCreateDice = [[Dice alloc]initWithSpriteFrameName:[self getDicePicture:randomDiceNumber]];
        [singleGameSpriteBatchNode addChild:tempCreateDice];
        [self addChild:singleGameSpriteBatchNode z:5];
        [createDiceArray addObject:tempCreateDice];
        [tempCreateDice setPosition:ccp( 40 , 220-(60*i))];
        [tempCreateDice setRecentPosition:ccp( 40 , 220-(60*i))];
        [tempCreateDice setDiceType:randomDiceNumber];

        [tempCreateDice release];
        maxDiceNumber++;
        mustMoveDiceNumber++;
    }
    CCLOG(@"length = %d" , [createDiceArray count]);
}

它成功地用图像创建骰子。但是当我使用该ccTouchesBegan方法时,我收到一些错误消息:

*** Assertion failure in -[Dice draw], /Users/xxxxx/Documents/C_Program/iOs Practice(2011)/DiceGame/DiceGame/libs/cocos2d/CCSprite.m:576
2012-08-13 02:32:47.921 DiceGame[11103:c07] *** Terminating app due to uncaught
 exception 'NSInternalInconsistencyException', reason: 'If CCSprite is being
 rendered by CCSpriteBatchNode, CCSprite#draw SHOULD NOT be called'

PS:骰子是一个继承自我CCSprite创建的类。

如果它不能使用CCSpriteBatchNode,也许我应该回去使用CCSprite

4

1 回答 1

1

你读过错误信息吗?

'If CCSprite is being rendered by CCSpriteBatchNode, 
 CCSprite#draw SHOULD NOT be called'

要么不覆盖该-(void) draw方法,要么不使用精灵批处理节点。

于 2012-08-12T21:32:09.090 回答