iOS SKSpriteNode 错误:从不兼容的类型"CGRect"(又名"struct CGRect")分配给"skspritenode *const __strong"



我正在sprite kit (objective-c)中开发Xcode项目。我得到这个错误,我不知道如何修复它,但我试图让两个节点在碰撞时记录。

iOS SKSpriteNode Error:

assigning to 'skspritenode *const __strong' from incompatible type 'CGRect' (aka 'struct                   CGRect')

我的代码在这里:

//This is the .m file
-(void) Clouds{
SKSpriteNode* character = [BBCharacter  spriteNodeWithImageNamed:@"character1"];
[self enumerateChildNodesWithName:@"cloud1" usingBlock:^(SKNode *node, BOOL *stop) {
    if (node.position.x < -380 || node.position.y < 0){ //node.position.x < -380
        [node removeFromParent];
        NSLog(@"DELETE");
    }
    else{
        node.position = CGPointMake(node.position.x - 1, node.position.y);
    }
    if (CGRectIntersectsRect (character, cloud1)) {
        NSLog(@"Intersection");
    }

}];
}
//This is the .h file
@interface{
}
@property (nonatomic, strong) BBCharacter *playerSprite;
@end

我跳过了一堆东西,可能拼写错了…谢谢!迈克尔。

我同意您需要从基础开始,但是看起来注释已经指向您使用框架来获得CGRects。因此,上面的代码看起来有两个问题:

  1. 你没有将CGRects传递给CGRectIntersectsRect
  2. 一旦你纠正1,你会有一个问题,你似乎正在检查"字符"的矩形,这是一个节点,你使方法云内部,但然后永远不会添加该节点到场景。因此它的矩形的大小是0,0。(除非你的自定义BBCharacter类覆盖spriteNodeWithImageNamed并自动将其添加到场景中)。

所以,要么在场景中添加字符:

[self addChild: character];

或者将character设置为指向场景中已经存在的其他对象的指针:

character = [self childNodeWithName:@"character"];
character = self.playerSprite; //etc

最新更新