我正在开发一个sprite-kit游戏,当我尝试从菜单场景转换到游戏场景时,我不断收到此错误消息,我不断得到以下内容:
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 :(得分:1)
尝试添加nil节点
在某处您使用addChild:
的对象调用nil
。
Add an exception breakpoint查看违规行。如果没有显示实际行,请在场景的初始化(或代码中的其他位置)设置断点,并逐步完成addChild:
的所有使用,其中添加的子项可能为零。一旦你得到了,问问自己为什么这个节点是零。 ;)
答案 1 :(得分:1)
检查SKEmitterNode orb_emitterNamed:
方法。很可能它有时会返回nil
。
或者,也许你可能没有&#34;背景&#34;和/或&#34; Trail&#34;包含在项目中的文件