SKScene 에서 SKNode 를 Touch 하여 Drag 하기
Drag 한 공간을 저장하기 위한 변수를 설정
전역변수로 설정하였습니다
이와 같이하면 됩니다.
CGPoint deltaPoint;
전역변수로 설정하였습니다
-(void)touchesMoved:(NSSet *)touches withEvent:(UIEvent *)event {
CGPoint p = [[touches anyObject] locationInNode:self];
[self enumerateChildNodesWithName:@"SKNode" usingBlock:^(SKNode *node, BOOL *stop) {
if ([node containsPoint:p]) {
CGPoint currentPoint = [[touches anyObject] locationInNode:self];
CGPoint previousPoint = [[touches anyObject] previousLocationInNode:self];
deltaPoint = CGPointMake(currentPoint.x - previousPoint.x, currentPoint.y - previousPoint.y);
}
}];
}
-(void)touchesEnded:(NSSet *)touches withEvent:(UIEvent *)event {
deltaPoint = CGPointZero;
}
-(void)touchesCancelled:(NSSet *)touches withEvent:(UIEvent *)event {
deltaPoint = CGPointZero;
}
#pragma rendering
-(void)update:(CFTimeInterval)currentTime {
[self enumerateChildNodesWithName:@"DetailNode" usingBlock:^(SKNode *node, BOOL *stop) {
if (node.hidden == NO) {
CGPoint newPoint = CGPointMake(node.position.x + deltaPoint.x, node.position.y + deltaPoint.y);
node.position = newPoint;
deltaPoint = CGPointZero;
}
}];
}
이와 같이하면 됩니다.
댓글
댓글 쓰기