2014-03-27 39 views
1

我工作的一個精靈套件的遊戲,我不斷收到試圖從菜單中的場景轉移到遊戲場景時,此錯誤消息,我不斷收到以下:這個錯誤信息是什麼? (Objective-C的)

2014-03-27 13:02:54.737 SpriteEzee[1723:60b] 
*** Terminating app due to uncaught exception 
'Attemped to add nil node', reason: 'Attemped to add nil node to parent: 
<SKNode> name:'(null)' position:{0, 0} accumulatedFrame:{{inf, inf}, {inf, inf}}' 

    *** First throw call stack: 
(
    0 CoreFoundation      0x019141e4 __exceptionPreprocess + 180 
    1 libobjc.A.dylib      0x016938e5 objc_exception_throw + 44 
    2 CoreFoundation      0x01913fbb +[NSException raise:format:] + 139 
    3 SpriteKit       0x0117afca -[SKNode addChild:] + 175 
    4 SpriteEzee       0x00002b98 -[MyScene initWithSize:] + 1768 
    5 SpriteEzee       0x00005ddf -[MenuScene touchesEnded:withEvent:] + 191 
    6 SpriteKit       0x0116cace -[SKView touchesEnded:withEvent:] + 680 
    7 UIKit        0x00272ddd -[UIWindow _sendTouchesForEvent:] + 852 
    8 UIKit        0x002739d1 -[UIWindow sendEvent:] + 1117 
    9 UIKit        0x002455f2 -[UIApplication sendEvent:] + 242 
    10 UIKit        0x0022f353 _UIApplicationHandleEventQueue + 11455 
    11 CoreFoundation      0x0189d77f __CFRUNLOOP_IS_CALLING_OUT_TO_A_SOURCE0_PERFORM_FUNCTION__ + 15 
    12 CoreFoundation      0x0189d10b __CFRunLoopDoSources0 + 235 
    13 CoreFoundation      0x018ba1ae __CFRunLoopRun + 910 
    14 CoreFoundation      0x018b99d3 CFRunLoopRunSpecific + 467 
    15 CoreFoundation      0x018b97eb CFRunLoopRunInMode + 123 
    16 GraphicsServices     0x039085ee GSEventRunModal + 192 
    17 GraphicsServices     0x0390842b GSEventRun + 104 
    18 UIKit        0x00231f9b UIApplicationMain + 1225 
    19 SpriteEzee       0x0000653d main + 141 
    20 libdyld.dylib      0x01f5b701 start + 1 
) 
libc++abi.dylib: terminating with uncaught exception of type NSException 
(lldb) 

這是我的過渡:

-(void)touchesEnded:(NSSet *)touches withEvent:(UIEvent *)event { 
MyScene *game = [[MyScene alloc] initWithSize:self.size]; 
[self.view presentScene:game transition:[SKTransition doorsOpenHorizontalWithDuration:0.5]]; 

}

我認爲這是正確寫入。所以我不確定爲什麼它給了我這個錯誤。

這是遊戲initWithSize方法:

-(id)initWithSize:(CGSize)size{ 
    if (self = [super initWithSize:size]) { 
     self.backgroundColor = [SKColor blackColor]; 

     self.physicsWorld.gravity = CGVectorMake(0, 0); 
     self.physicsWorld.contactDelegate = self; 

     _enemies = [NSMutableArray new]; 

     _player = [SKNode node]; 
     SKShapeNode *circle = [SKShapeNode node]; 
     circle.path = [UIBezierPath bezierPathWithOvalInRect:CGRectMake(0, 0, 20, 20)].CGPath; 
     circle.fillColor = [UIColor blueColor]; 
     circle.strokeColor = [UIColor blueColor]; 
     circle.glowWidth = 5; 

     SKEmitterNode *trail = [SKEmitterNode orb_emitterNamed:@"Trail"]; 
     trail.targetNode = self; 
     trail.position = CGPointMake(CGRectGetMidX(circle.frame), CGRectGetMidY(circle.frame)); 
     [_player addChild:trail]; 

     _player.physicsBody = [SKPhysicsBody bodyWithCircleOfRadius:10]; 
     _player.physicsBody.mass = 100000; 
     _player.physicsBody.categoryBitMask = CollisionPlayer; 
     _player.physicsBody.contactTestBitMask = CollisionEnemy; 

     _player.position = CGPointMake(size.width/2, size.height/2); 

     SKEmitterNode *background = [SKEmitterNode orb_emitterNamed:@"Background"]; 
     background.particlePositionRange = CGVectorMake(self.size.width*2, self.size.height*2); 
     [background advanceSimulationTime:10]; 

     [self addChild:background]; 
     [self addChild:_player]; 
    } 
    return self; 
} 
+0

粘貼'MyScene'的'initWithSize'方法 –

+0

增加它在@AndreyGordeev,見上 –

+0

你能否也請粘貼callstack的錯誤? –

回答

1

檢查SKEmitterNode orb_emitterNamed:方法。很有可能它有時會返回nil

或者,可能是你根本沒有「背景」和/或「足跡」的文件包含到您的項目

1

Attemped加零節點

某處你打電話addChild:與對象是nil

Add an exception breakpoint看到違規行。如果沒有顯示實際行,請在場景的init(或代碼中的其他位置)中設置斷點,並逐步完成addChild:的所有用途,其中添加的子項可能爲零。一旦你明白了,爲什麼這個節點是零。 ;)

相關問題