好吧,我现在很难找到执行此拖动效果的资源。 效果是这样的:
答案 0 :(得分:0)
不知道拖动效果的任何名称,但实现起来非常简单。以下是一个非常基本的实现,可以进行增强。
首先,在场景中声明两个实例变量
SKNode *selectedNode;
UITouch *currentTouch;
然后,您可以使用触摸代理实现所需的功能。
-(void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event
{
UITouch *touch = [touches anyObject];
CGPoint touchPoint = [touch locationInNode:self];
SKNode *node = [self nodeAtPoint:touchPoint];
if ([node.name isEqualToString:@"whatevername"])
{
selectedNode = node;
currentTouch = touch;
}
}
-(void)touchesEnded:(NSSet *)touches withEvent:(UIEvent *)event
{
UITouch *touch = [touches anyObject];
if ([touch isEqual:currentTouch])
{
CGPoint point = [touch locationInNode:self];
[selectedNode runAction:[SKAction moveTo:point duration:1.0]];
//Also can calculate time based on distance to make the movement uniform.
selectedNode = nil;
currentTouch = nil;
}
}
-(void)touchesCancelled:(NSSet *)touches withEvent:(UIEvent *)event
{
UITouch *touch = [touches anyObject];
if ([touch isEqual:currentTouch])
{
selectedNode = nil;
currentTouch = nil;
}
}