不兼容的块指针SKSpriteNode

时间:2015-11-07 15:02:03

标签: ios objective-c skspritenode

这是我的代码

- (void) update:(NSTimeInterval)currentTime
{
    [self.children enumerateObjectsUsingBlock:^(SKSpriteNode * child, NSUInteger idx, BOOL *stop) {
    child.position = CGPointMake(child.position.x-self.scrollingSpeed, child.position.y);
    if (child.position.x <= -child.size.width){
        float delta = child.position.x+child.size.width;
        child.position = CGPointMake(child.size.width*(self.children.count-1)+delta, child.position.y);
        }
    }];
}

我收到了一个错误

Incompatible block pointer types sending 'void (^)(SKSpriteNode *__strong, NSUInteger, BOOL *)' to parameter of type 'void (^ _Nonnull)(SKNode * _Nonnull __strong, NSUInteger, BOOL * _Nonnull)'

我不知道为什么。我尝试将其更改为SKNode,但它表示尺寸不存在。

非常感谢任何想法。

1 个答案:

答案 0 :(得分:3)

枚举块语法不正确,您需要更改:

 [self.children enumerateObjectsUsingBlock:^(SKSpriteNode * child, NSUInteger idx, BOOL *stop)
{
    child.position = CGPointMake(child.position.x-self.scrollingSpeed, child.position.y);
    if (child.position.x <= -child.size.width)
    {
       float delta = child.position.x+child.size.width;
       child.position = CGPointMake(child.size.width*(self.children.count-1)+delta, child.position.y);
    }
}];

 [self.children enumerateObjectsUsingBlock:^(id object, NSUInteger idx, BOOL *stop)
 {
    SKSpriteNode *child = (SKSpriteNode *)object;
    child.position = CGPointMake(child.position.x-self.scrollingSpeed, child.position.y);
    if (child.position.x <= -child.size.width)
    {
       float delta = child.position.x+child.size.width;
       child.position = CGPointMake(child.size.width*(self.children.count-1)+delta, child.position.y);
    }
}];

枚举块的第一个参数属于id而非SKSpriteNodeNSArray没有这样的实现。