• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

ios - SKSpriteNode 不稳定的滑动?

[复制链接]
菜鸟教程小白 发表于 2022-12-13 05:54:57 | 显示全部楼层 |阅读模式 打印 上一主题 下一主题

我创建了以下 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-推荐答案


我使用 [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/

回复

使用道具 举报

懒得打字嘛,点击右侧快捷回复 【右侧内容,后台自定义】
您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

关注0

粉丝2

帖子830918

发布主题
阅读排行 更多
广告位

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap