Using SpriteKit, I have created a SKSpriteNode called lightSaber, and using the touchesMoved method, I am able to either rotate the SKSpriteNode or translate it left or right. Is there a way to make it so it does one or the either depending on where I grab the SKSpriteNode? (e.g. the blade or the handle)
Asked
Active
Viewed 99 times
1 Answers
0
You could get the position of the touchEvent via
CGPoint location = [touch locationInNode:self];
This will give you the capability to add custom logic to where you touch the screen. For example:
if(location.x > 300) {
//Do this
} else {
//Do that
}
You could also make the sword in two pieces, i.e two nodes and name each node and listen to a touch event on both nodes.
Get the node within touchesBegan
by
SKNode *node = [self nodeAtPoint:location];
if([node.name isEqualToString@"Handle"]) {
} else if ([node.name isEqualToString@"Blade"]) {
}

Philip
- 2,287
- 1
- 22
- 37
-
But the blade and handle are not always one on top of the other, since touching the blade would rotate the Lightsaber, so location.x > 300 wouldn't necessarily help. Separating it into two objects is also not very practical since they always need to be touching and oriented correctly. – Lahav Jul 10 '15 at 23:05