iOS SKSpriteNode错误:从不兼容的类型“ CGRect”(也称为“ struct CGRect”)分配给“ skspritenode * const __strong”

迈克尔·D33

我正在sprite工具包(objective-c)中的Xcode项目上工作,但遇到此错误,我不知道如何解决,但我试图让两个节点发生冲突时进行记录。

iOS SKSpriteNode错误:

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后,您将遇到一个问题,即似乎正在检查“字符”的矩形,该字符是您在方法云内部创建的一个节点,但从未将该节点添加到场景中。因此,其rect的大小将为0,0。(除非您的自定义BBCharacter类重写spriteNodeWithImageNamed并将其自动添加到场景中)。

因此,可以在场景中添加角色:

[self addChild: character];

或者使角色成为场景中已经存在的其他事物的指针:

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

本文收集自互联网,转载请注明来源。

如有侵权,请联系[email protected] 删除。

编辑于
0

我来说两句

0条评论
登录后参与评论

相关文章

Related 相关文章

热门标签

归档