如何修复此错误:"尝试从对象[1]"中插入nil对象

时间:2015-03-21 21:55:05

标签: ios objective-c sprite-kit skaction

我正在制作一个SKAction序列,我在序列中放了两个其他SKActions,它给了我这个错误:

Terminating app due to uncaught exception
'NSInvalidArgumentException', reason: '*** -[__NSPlaceholderArray
initWithObjects:count:]: attempt to insert nil object from

对象[1]“

当我设置异常断点时,它指向这一行:

  

SKAction * sequence = [SKAction序列:@ [moveUp,moveDown]];

以下是整个方法代码:

-(void) animateLetters{

    moveUp = [SKAction moveByX:0 y:15 duration:2];
    moveUp = [SKAction moveByX:0 y:-15 duration:2];

    SKAction *sequence = [SKAction sequence:@[moveUp, moveDown]];

    SKAction *runForever = [SKAction repeatActionForever:sequence];
    [letter1 runAction:runForever];
}

1 个答案:

答案 0 :(得分:1)

您要分配moveUp两次,moveDown永远不会。在这种情况下,使用局部变量可能更有意义 -

-(void) animateLetters{

    SKAction *moveUp = [SKAction moveByX:0 y:15 duration:2];
    SKAction *moveDown = [SKAction moveByX:0 y:-15 duration:2];

    SKAction *sequence = [SKAction sequence:@[moveUp, moveDown]];

    SKAction *runForever = [SKAction repeatActionForever:sequence];
    [letter1 runAction:runForever];
}