我正在制作一个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];
}
答案 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];
}