我创建了以下 Sprite 套件节点:
SKSpriteNode *megadeth;
megadeth = [SKSpriteNode spriteNodeWithImageNamed"megadeth_rocks.png"];
megadeth.name = @"awesome";
并添加滑动手势如下:
-(void)didMoveToViewSKView *)view{
UISwipeGestureRecognizer *recognizerUp = [[UISwipeGestureRecognizer alloc] initWithTarget:self actionselector(handleSwipeUp];
recognizerUp.direction = UISwipeGestureRecognizerDirectionUp;
[[self view] addGestureRecognizer:recognizerUp];
UISwipeGestureRecognizer *recognizerDn = [[UISwipeGestureRecognizer alloc] initWithTarget:self actionselector(handleSwipeDn];
recognizerDn.direction = UISwipeGestureRecognizerDirectionDown;
[[self view] addGestureRecognizer:recognizerDn];
}
- (void)handleSwipeUpUISwipeGestureRecognizer *)sender{
NSLog(@"Node Swiped Up");
if (sender.state == UIGestureRecognizerStateEnded)
{
CGPoint touchLocation = [sender locationInView:sender.view];
touchLocation = [self convertPointFromView:touchLocation];
SKSpriteNode *touchedNode = (SKSpriteNode *)[self nodeAtPoint:touchLocation];
if([touchedNode.name isEqualToString"awesome"]){
NSLog(@"erform Action on AWESOME node");
SKAction *moveUp = [SKAction moveByX:0.0 y0-touchedNode.position.y) duration:0.5];
SKAction *fade = [SKAction fadeOutWithDuration:0.25];
//SKAction *remove = [SKAction removeFromParent];
SKAction *sequence = [SKAction sequence[moveUp, fade]];
[touchedNode runAction:sequence];
}
}
}
当我滑动节点时,它会滑动,但它会回到原来的位置,然后淡出以移除。
我想要的是,当我刷卡时,它应该移动到刷卡的位置并移除。我在这里错过了什么吗?
Best Answer-推荐答案 strong>
我使用 [SKAction moveToY:duration:] 而不是 [SKAction moveByX:y:] ,这让一切都像魅力一样工作
这是更新后的 handleSwipeUp: 方法:
- (void)handleSwipeUpUISwipeGestureRecognizer *)sender{
NSLog(@"Node Swiped Up");
//if (sender.state == UIGestureRecognizerStateEnded)
//{
CGPoint touchLocation = [sender locationInView:sender.view];
touchLocation = [self convertPointFromView:touchLocation];
SKSpriteNode *touchedNode = (SKSpriteNode *)[self nodeAtPoint:touchLocation];
if([touchedNode.name isEqualToString"awesome"]){
NSLog(@"erform Action on AWESOME node");
**SKAction *moveUp = [SKAction moveToYtouchedNode.position.y+200) duration:0.5];**
//SKAction *fade = [SKAction fadeOutWithDuration:0.25];
SKAction *remove = [SKAction removeFromParent];
SKAction *sequence = [SKAction sequence[moveUp, remove]];
[touchedNode runAction:sequence];
}
//}
}
希望对你有帮助!!!
关于ios - SKSpriteNode 不稳定的滑动?,我们在Stack Overflow上找到一个类似的问题:
https://stackoverflow.com/questions/29065278/
|