【发布时间】:2014-07-16 13:54:35
【问题描述】:
我正在使用 sprite kit (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
我跳过了一堆东西,可能拼错了…… 谢谢! 迈克尔
【问题讨论】:
-
CGRectIntersectsRect参数需要为CGRect。您似乎在传递字符和云,它们似乎是SKSpriteNode。 -
有什么我可以做的吗?我需要改变什么?
-
如果我所说的对您来说没有 100% 的意义,这是本末倒置的情况。您需要退后一步,更好地理解变量类型。如果你愿意花时间学习,网上有很多教程和参考资料。
-
我明白你的意思,我只是不明白我能做些什么......
-
试试 character.frame 和 cloud1.frame
标签: objective-c xcode sprite-kit collision skspritenode