Objective c CCSprite未使用相同的纹理id错误

Objective c CCSprite未使用相同的纹理id错误,objective-c,cocos2d-iphone,Objective C,Cocos2d Iphone,我遇到一个错误,我的游戏将轰炸我,并给我以下消息: 由于未捕获异常而终止应用程序 “NSInternalInconsistencyException”,原因:“CCSprite未使用 相同纹理id' 以下是源代码: 英雄.h #import "cocos2d.h" #import "ActionSprite.h" #import "GameLayer.h" #import "Goblin.h" @class GameLayer, Waypoint, Goblin; @interface He

我遇到一个错误,我的游戏将轰炸我,并给我以下消息:

由于未捕获异常而终止应用程序 “NSInternalInconsistencyException”,原因:“CCSprite未使用 相同纹理id'

以下是源代码:

英雄.h

#import "cocos2d.h"
#import "ActionSprite.h"
#import "GameLayer.h"
#import "Goblin.h"

@class GameLayer, Waypoint, Goblin;

@interface Hero : ActionSprite {
    Waypoint *destinationWaypoint;

    Goblin *chosenGoblin;

    NSMutableArray *attackedBy;

    int maxHp;
}

@property (nonatomic, weak) GameLayer *theGame;
@property (nonatomic, strong) CCSprite *mySprite;

+(id) nodeWithTheGame: (GameLayer *)_game location: (CGPoint)location;
-(id) initWithTheGame: (GameLayer *)_game location: (CGPoint)location;
-(void) startMoving;

@end
英雄.m

#import "Hero.h"
#import "Waypoint.h"
#import "Goblin.h"

#define HEALTH_BAR_WIDTH 20
#define HEALTH_BAR_ORIGIN -10

@implementation Hero

@synthesize theGame;
@synthesize mySprite;

+(id) nodeWithTheGame: (GameLayer *)_game location: (CGPoint)location
{
    return [[self alloc] initWithTheGame:_game location:location];
}

-(id) initWithTheGame:(GameLayer *)_game location:(CGPoint)location
{
    //if ((self = [super initWithSpriteFrameName:@"TriElfWalk000.1@2x.png"])) {
    if (self = [super init]) {
        int i;
        // Idle Animation
        CCArray *idleFrames = [CCArray arrayWithCapacity: 11];
        for (i = 0; i < 11; i++) {
            CCSpriteFrame *frame = [[CCSpriteFrameCache sharedSpriteFrameCache] spriteFrameByName:[NSString stringWithFormat: @"TriElfWalk%03d.1@2x.png", i]];
            [idleFrames addObject: frame];
        }

        CCAnimation *idleAnimation = [CCAnimation animationWithSpriteFrames: [idleFrames getNSArray] delay: 1.0/11.0];
        self.idleAction = [CCRepeatForever actionWithAction: [CCAnimate actionWithAnimation: idleAnimation]];

        // Attack Animation
        CCArray *attackFrames = [CCArray arrayWithCapacity: 11];
        for (i = 0; i < 11; i++) {
            CCSpriteFrame *frame = [[CCSpriteFrameCache sharedSpriteFrameCache] spriteFrameByName:[NSString stringWithFormat:@"TriElfWalk%03d.1@2x.png", i]];
            [attackFrames addObject: frame];
        }

        CCAnimation *attackAnimation = [CCAnimation animationWithSpriteFrames: [attackFrames getNSArray] delay: 1.0/11.0];
        self.attackAction = [CCSequence actions:[CCAnimate actionWithAnimation: attackAnimation], [CCCallFunc actionWithTarget:self selector:@selector(idle)], nil];

        // Walk Animation
        CCArray *walkFrames = [CCArray arrayWithCapacity: 11];
        for (i = 0; i < 11; i++) {
            CCSpriteFrame *frame = [[CCSpriteFrameCache sharedSpriteFrameCache] spriteFrameByName:[NSString stringWithFormat: @"TriElfWalk%03d.1@2x.png", i]];
            [walkFrames addObject: frame];
        }

        CCAnimation *walkAnimation = [CCAnimation animationWithSpriteFrames: [walkFrames getNSArray] delay: 1.0/11.0];
        self.walkAction = [CCRepeatForever actionWithAction: [CCAnimate actionWithAnimation: walkAnimation]];


        // Death Animation
        CCArray *deathFrames = [CCArray arrayWithCapacity:11];
        for (int i = 0; i < 11; i++) {
            CCSpriteFrame *frame = [[CCSpriteFrameCache sharedSpriteFrameCache] spriteFrameByName: [NSString stringWithFormat: @"TriElfWalk%03d.1@2x.png", i]];
            [deathFrames addObject: frame];
        }

        CCAnimation *deathAnimation = [CCAnimation animationWithSpriteFrames: [deathFrames getNSArray] delay: 1.0/12.0];
        self.deathAction = [CCSequence actions: [CCAnimate actionWithAnimation: deathAnimation], [CCBlink actionWithDuration: 2.0 blinks: 10.0], nil];

        self.centerToBottom = 24.5;
        self.centerToSides = 21.5;
        self.hitPoints = 100.0;
        self.damage = 20.0;
        //self.walkSpeed = 8;
        self.cost = 100;
        self.incomeProvided = 3;

        // Create bounxing boxes
        self.hitBox = [self createBoundingBoxWithOrigin:ccp(-self.centerToSides, -self.centerToBottom) size:CGSizeMake(self.centerToSides * 2, self.centerToBottom * 2)];
        self.attackBox = [self createBoundingBoxWithOrigin:ccp(self.centerToSides, -10) size:CGSizeMake(10, 10)];

        maxHp = self.hitPoints;

        [self scheduleUpdate];
    }

    return self;
}

-(void) startMoving
{
    //CCLOG(@"I SHOULD BE MOVING!");

    self.desiredPosition = ccp(1050, 360);
    [self runAction: [CCMoveTo actionWithDuration:50 position:self.desiredPosition]];
}

-(void) update: (ccTime)dt
{
    CCLOG(@"FOOTMAN Y: %f", self.position.y);

    for (Goblin *goblin in theGame.goblins) {
        CCLOG(@"GOBLIN Y: %f", goblin.position.y);
    }
}

-(void) getRemoved
{
    for (Tower *attacker in attackedBy) {
        [attacker targetKilled];
    }

    [self.parent removeChild: self cleanup: true];
    [theGame.goblins removeObject: self];

    // Notify the game that we killed an enemy so we can check if we can send another wave
    [theGame goblinGotKilled];
}

-(void) draw
{
    ccDrawSolidRect( ccp(self.position.x + HEALTH_BAR_ORIGIN, self.position.y + 16), ccp(self.position.x + HEALTH_BAR_ORIGIN + HEALTH_BAR_WIDTH, self.position.y + 14),  ccc4f(1.0, 0, 0, 1.0));
    ccDrawSolidRect( ccp(self.position.x + HEALTH_BAR_ORIGIN, self.position.y + 16), ccp(self.position.x + HEALTH_BAR_ORIGIN + (float)(self.currentHitPoints * HEALTH_BAR_WIDTH)/maxHp, self.position.y + 14), ccc4f(0, 1.0, 0, 1.0));
}

@end

如果有人能帮我找出问题所在,因为我认为我还没有接近解决问题。

此错误是由于在批处理节点中添加了一个精灵,而精灵和批处理节点纹理不相同而导致的。我如何检查哪个批处理节点正在尝试使用哪个精灵,以便解决此问题?设置一个全局设置异常断点,检查调用堆栈
*** First throw call stack:
(
    0   CoreFoundation                      0x039d85e4 __exceptionPreprocess + 180
    1   libobjc.A.dylib                     0x01fd38b6 objc_exception_throw + 44
    2   CoreFoundation                      0x039d8448 +[NSException raise:format:arguments:] + 136
    3   Foundation                          0x01732fee -[NSAssertionHandler handleFailureInMethod:object:file:lineNumber:description:] + 116
    4   KingdomOfRosak                      0x00083457 -[CCSpriteBatchNode addChild:z:tag:] + 743
    5   KingdomOfRosak                      0x000732de -[CCNode addChild:] + 318
    6   KingdomOfRosak                      0x000110d6 -[GameLayer initHero] + 102
    7   KingdomOfRosak                      0x000123c9 -[GameLayer footsoldierPurchased:] + 505
    8   libobjc.A.dylib                     0x01fe581f -[NSObject performSelector:withObject:] + 70
    9   KingdomOfRosak                      0x000b5907 __83-[CCMenuItemImage initWithNormalImage:selectedImage:disabledImage:target:selector:]_block_invoke + 71
    10  KingdomOfRosak                      0x000b1fac -[CCMenuItem activate] + 108
    11  KingdomOfRosak                      0x000c62d9 -[CCMenu ccTouchEnded:withEvent:] + 297
    12  libobjc.A.dylib                     0x01fe5874 -[NSObject performSelector:withObject:withObject:] + 77
    13  KingdomOfRosak                      0x00054d4f -[CCTouchDispatcher touches:withEvent:withTouchType:] + 1487
    14  KingdomOfRosak                      0x000558e3 -[CCTouchDispatcher touchesEnded:withEvent:] + 115
    15  KingdomOfRosak                      0x0001c2be -[CCGLView touchesEnded:withEvent:] + 110
    16  UIKit                               0x0028051d -[UIWindow _sendTouchesForEvent:] + 852
    17  UIKit                               0x00281184 -[UIWindow sendEvent:] + 1232
    18  UIKit                               0x00254e86 -[UIApplication sendEvent:] + 242
    19  UIKit                               0x0023f18f _UIApplicationHandleEventQueue + 11421
    20  CoreFoundation                      0x0396183f __CFRUNLOOP_IS_CALLING_OUT_TO_A_SOURCE0_PERFORM_FUNCTION__ + 15
    21  CoreFoundation                      0x039611cb __CFRunLoopDoSources0 + 235
    22  CoreFoundation                      0x0397e29e __CFRunLoopRun + 910
    23  CoreFoundation                      0x0397dac3 CFRunLoopRunSpecific + 467
    24  CoreFoundation                      0x0397d8db CFRunLoopRunInMode + 123
    25  GraphicsServices                    0x032f69e2 GSEventRunModal + 192
    26  GraphicsServices                    0x032f6809 GSEventRun + 104
    27  UIKit                               0x00241d3b UIApplicationMain + 1225
    28  KingdomOfRosak                      0x00091506 main + 134
    29  KingdomOfRosak                      0x00001eb5 start + 53
    30  ???                                 0x00000001 0x0 + 1
)
libc++abi.dylib: terminating with uncaught exception of type NSException