2014-02-25 67 views
0

我试图添加一个10计数循环到我的游戏,但是当我运行代码时,它会生成一个“变量不可分配missing__block”错误消息。任何人都可以告诉我哪里错了,并指出我在正确的方向吗?变量不能分配missing__block

-(void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event 
{ 
    CGPoint currentLocation = [[touches anyObject] locationInNode:self]; 
    CGPoint previousLocation = [[touches anyObject] previousLocationInNode:self]; 
    CGRect shipRect = _ship.frame; 
    if (CGRectContainsPoint(shipRect, previousLocation)) 
    { 
     [self launch:10 p1:currentLocation p2:previousLocation rect1:shipRect]; 
    } 
} 

-(void)launch:(int)count p1:(CGPoint) currentLocation p2:(CGPoint) previousLocation rect1:(CGRect) shipRect 
{ 
    CGPoint lvPosition = CGPointMake(_ship.position.x - (previousLocation.x - currentLocation.x), _ship.position.y); 
_ship.position = lvPosition; 

    SKAction *sound = [SKAction playSoundFileNamed:@"slideup.mp3" waitForCompletion:NO]; 
    SKAction *moveNode = [SKAction moveByX:lvPosition.x y:10.0 duration:3.0]; 

    [_ship runAction: sound]; 
    [_ship runAction: moveNode completion:^{[self launch:count-- p1:currentLocation p2:previousLocation rect1:shipRect];}]; /*variable not assignable missing__block error*/ 

} 
+0

更改参数是不好的主意,不管是否阻止,你都应该避免它 – sage444

+0

你说你正在尝试添加一个循环,但是代码示例中没有循环。你错过了错误的东西吗? – CRD

回答

1

我认为你正试图去递减没有被定义为__block变量count。您必须声明要与__block块内改变每个变量,例如__block int count;

[编辑] 你的情况最简单的解决方法是ASIGN count-1的递归调用,因为你并不需要的结果count--稍后

0

__block局部变量不能在块中分配。

但是,使它__block可能不是你想要的。方法名称runAction:completion:听起来好像它会在动作完成后调用“完成”块一次。由于它被调用一次,并且此后不使用count,所以后减量是毫无意义的。