Incompatible block pointer SKSpriteNode

笑着哭i 提交于 2019-12-12 04:18:46

问题


This is my code

- (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);
        }
    }];
}

And i am getting an an error

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

and I don't know why. I tried changing it to SKNode but it says size does not exist.

Any ideas would be greatly appreciated.


回答1:


The enumeration block syntax is not correct, you need to change:

 [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);
    }
}];

to

 [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);
    }
}];

The enumeration block's first parameter is of type id not SKSpriteNode. There is no such implementation for NSArray.



来源:https://stackoverflow.com/questions/33584180/incompatible-block-pointer-skspritenode

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!