我使用以下代码在 SKScene 上添加了图像 -
char1 = [[SKSpriteNode alloc] initWithImageNamed:@"CH_designb_nerd.png"];
char1.position = CGPointMake(225.0, 65.0);
char1.anchorPoint = CGPointMake(0, 0);
[char1 setScale:0.35];
[self addChild:char1];
然后我试图在图像上创建一个触摸事件,但图像的 CGRect 似乎在屏幕的另一侧完全翻转。我使用了以下代码
(void)touchesEnded:(NSSet *)touches withEvent:(UIEvent *)event {
UITouch *touch = [[event allTouches] anyObject];
CGPoint location = [touch locationInView:self.view];
if (CGRectContainsPoint(char1.frame, location)) {
NSLog(@"yaaa!!");
}
else{
NSLog(@"%.2f",location.x);
NSLog(@"%.2f",char1.position.x);
}
}
我完全迷失了这一点,因为图像放置得很好,但坐标或 CGRect 似乎翻转了。图像位于底部,但只有当我触摸屏幕顶部时,它才会说发生了触摸。