我試圖添加一個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*/
}
更改參數是不好的主意,不管是否阻止,你都應該避免它 – sage444
你說你正在嘗試添加一個循環,但是代碼示例中沒有循環。你錯過了錯誤的東西嗎? – CRD