菜鸟教程小白 发表于 2022-12-13 05:54:57

ios - SKSpriteNode 不稳定的滑动?


                                            <p><p><strong>我创建了以下 Sprite 套件节点:</strong></p>

<pre><code>SKSpriteNode *megadeth;
megadeth = ;
megadeth.name = @&#34;awesome&#34;;
</code></pre>

<p><strong>并添加滑动手势如下:</strong></p>

<pre><code>-(void)didMoveToView:(SKView *)view{
   UISwipeGestureRecognizer *recognizerUp = [ initWithTarget:self action:@selector(handleSwipeUp:)];
recognizerUp.direction = UISwipeGestureRecognizerDirectionUp;
[ addGestureRecognizer:recognizerUp];

UISwipeGestureRecognizer *recognizerDn = [ initWithTarget:self action:@selector(handleSwipeDn:)];
recognizerDn.direction = UISwipeGestureRecognizerDirectionDown;
[ addGestureRecognizer:recognizerDn];
}

- (void)handleSwipeUp:(UISwipeGestureRecognizer *)sender{

   NSLog(@&#34;Node Swiped Up&#34;);
   if (sender.state == UIGestureRecognizerStateEnded)
       {
      CGPoint touchLocation = ;
      touchLocation = ;
      SKSpriteNode *touchedNode = (SKSpriteNode *);
      if(){
      NSLog(@&#34;Perform Action on AWESOME node&#34;);
      SKAction *moveUp = ;
      SKAction *fade = ;
      //SKAction *remove = ;
      SKAction *sequence = ];
      ;
      }
    }
}
</code></pre>

<p>当我滑动节点时,它会滑动,但它会回到原来的位置,然后淡出以移除。</p>

<p>我想要的是,当我刷卡时,它应该移动到刷卡的位置并移除。我在这里错过了什么吗?</p></p>
                                    <br><hr><h1><strong>Best Answer-推荐答案</ strong></h1><br>
                                            <p><p><strong>我使用 <code></code> 而不是 <code></code> ,这让一切都像魅力一样工作</strong> </p>

<p><strong>这是更新后的 <code>handleSwipeUp:</code> 方法:</strong></p>

<pre><code>- (void)handleSwipeUp:(UISwipeGestureRecognizer *)sender{

NSLog(@&#34;Node Swiped Up&#34;);
//if (sender.state == UIGestureRecognizerStateEnded)
   //{
    CGPoint touchLocation = ;
    touchLocation = ;
    SKSpriteNode *touchedNode = (SKSpriteNode *);
    if(){
    NSLog(@&#34;Perform Action on AWESOME node&#34;);
    **SKAction *moveUp = ;**
    //SKAction *fade = ;
    SKAction *remove = ;
    SKAction *sequence = ];
    ;
}
//}
</code></pre>

<p>}</p>

<p>希望对你有帮助!!!</p></p>
                                   
                                                <p style="font-size: 20px;">关于ios - SKSpriteNode 不稳定的滑动?,我们在Stack Overflow上找到一个类似的问题:
                                                        <a href="https://stackoverflow.com/questions/29065278/" rel="noreferrer noopener nofollow" style="color: red;">
                                                                https://stackoverflow.com/questions/29065278/
                                                        </a>
                                                </p>
                                       
页: [1]
查看完整版本: ios - SKSpriteNode 不稳定的滑动?