ios - 这是什么错误信息? ( objective-C )

标签 ios objective-c sprite-kit

我正在开发一个 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;
}

最佳答案

检查 SKEmitterNode orb_emitterNamed: 方法。很可能它有时会返回 nil

或者,您可能只是没有将“背景”和/或“轨迹”文件包含到您的项目中

关于ios - 这是什么错误信息? ( objective-C ),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22694433/

相关文章:

ios - 从 Parse 刷新和更新 NSMutableA rray 中的对象

ios - 如何制作 secret 的 iOS 应用程序文本动画

ios - AdMob 横幅广告未显示 Swift 3

ios - 单击更改节点图像-SWIFT

ios - 通过 UIActivityViewController (Twitter, Facebook, Instagram) 使用主题标签分享图片

ios - 背景/前景上的 NSTimer 行为

ios - 调用 NSURLConnection cancel 时会触发 didFailWithError 吗?

Objective-C 格式化 CGFloat

ios - Sprite Kit - 检测接触

ios - 如何根据设备的方向添加或删除 subview ?