Sprite Kit detect position of touch
ios, objective-c, sprite-kit
Solution
Override the `touchesEnded:withEvent` or `touchesBegan:withEvent:` method to do this:
- (void)touchesEnded:(NSSet *)touches withEvent:(UIEvent *)event{
UITouch *touch = [touches anyObject];
if(touch){
if([touch locationInView:self.view]>self.size.width/2){
[self runTouchOnRightSideAction];
}else{
[self runTouchOnLeftSideAction];
}
}
}
Problem
I want to run different actions depending on if you touch the left or right half of the screen. So an action when you touch the left half, and another when the right half is touched. I suppose I could make a transparent button image that covers half of the screen and use this code to run an action when touched, but I don't think that's the way to go. Is there a better way to detect the position of a touch?