0

当对象不存在时,如何找到指针指向的对象?请继续阅读。这不是一个愚蠢的问题。我在这个游戏中创建了太多的数组,现在在不计算对象的情况下找到我留下的数组有点困难。我知道错误正在显示,因为该对象不再存在,但有没有人知道准确找到什么变量(在数组中),甚至是什么数组导致问题的好方法?我在这里寻找调试解决方案。我看到其他类似的问题,但找不到解决问题的答案。

导致错误的函数如下所示,但请记住,我不是要修复该函数,而是要正确调试并找到问题。

-(void)handleContact:(SKPhysicsContact*)contact {
NSLog(@"Handling contact");
// Ensure you haven't already handled this contact and removed its nodes
if (!contact.bodyA.node.parent || !contact.bodyB.node.parent) return;

NSArray* nodeNames = @[contact.bodyA.node.name, contact.bodyB.node.name];
if ([nodeNames containsObject:kPlayerName] && [nodeNames containsObject:kEnemyWeaponName]) {
    // ENEMY BULLET HITS YOU
    [self adjustShipHealthBy:-0.20f];
    if (self.playerHealth <= 0.0f) {
        //2
        [contact.bodyA.node removeFromParent];
        [contact.bodyB.node removeFromParent];
    } else {
        //3
        SKNode* ship = [self childNodeWithName:kPlayerName];
        ship.alpha = self.playerHealth;
        if (contact.bodyA.node == ship) [contact.bodyB.node removeFromParent];
        else [contact.bodyA.node removeFromParent];
    }
} else if ([nodeNames containsObject:kEnemyName] && [nodeNames containsObject:kPlayerWeaponName]) {
    // YOU HIT THE ENEMY
    //[self runAction:[SKAction playSoundFileNamed:@"InvaderHit.wav" waitForCompletion:NO]];

    NSString *burstPath = [[NSBundle mainBundle] pathForResource:@"MySpark" ofType:@"sks"];
    SKEmitterNode *explosion = [NSKeyedUnarchiver unarchiveObjectWithFile:burstPath];
    explosion.numParticlesToEmit = 100;
    explosion.position = contact.bodyA.node.position;
    [self addChild:explosion];

    [contact.bodyA.node removeFromParent];
    [contact.bodyB.node removeFromParent];
    [self adjustScoreBy:100];

}else if ([nodeNames containsObject:kPlayerName] && [nodeNames containsObject:kHealthPackName]){
    // GET HEALTH PACK
    NSLog(@"=========== HEALTH ============");
    [self adjustShipHealthBy:0.40f];
    NSString *healthPath = [[NSBundle mainBundle] pathForResource:@"HealthKit" ofType:@"sks"];
    SKEmitterNode *healthGain = [NSKeyedUnarchiver unarchiveObjectWithFile:healthPath];
    healthGain.numParticlesToEmit = 5;
    healthGain.position = contact.bodyA.node.position;
    [self addChild:healthGain];

    SKNode *thatHealthNode = [self childNodeWithName:kHealthPackName];
    [thatHealthNode removeFromParent];
    }

}
4

0 回答 0