Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/swift/17.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Swift 通过按钮触摸移动SKSpriteNode_Swift_Xcode_Sprite Kit_Mobile Development - Fatal编程技术网

Swift 通过按钮触摸移动SKSpriteNode

Swift 通过按钮触摸移动SKSpriteNode,swift,xcode,sprite-kit,mobile-development,Swift,Xcode,Sprite Kit,Mobile Development,在我的游戏场景中我得到了英雄的斯普林泰诺德。我实现了两个按钮(向上和向下)。我需要我的英雄的斯普林泰诺德通过按键上下移动。但我只看到触控移动和触控移动的方法。我需要一些关于touchsbegind(在我点击按钮时感觉到按钮在点击)的信息。您创建某种重复步骤,从touchsbegind开始,到touchseded结束,或者当触摸移出节点时 通过检查touchesMoved override func touchesBegan(...) { ... let moveAction = SK

在我的游戏场景中我得到了英雄的斯普林泰诺德。我实现了两个按钮(向上和向下)。我需要我的英雄的斯普林泰诺德通过按键上下移动。但我只看到触控移动和触控移动的方法。我需要一些关于touchsbegind(在我点击按钮时感觉到按钮在点击)的信息。

您创建某种重复步骤,从
touchsbegind
开始,到
touchseded
结束,或者当触摸移出节点时 通过检查
touchesMoved

override func touchesBegan(...)
{
   ...
   let moveAction = SKAction.repeatForever(SKAction.move(by:CGPoint(x:x,y:y)))
   node.run(moveAction,forKey:"moving")
   ...
}
override func touchesMoved(...)
{
   ...
   //add a check to see if if touch.position is not inside the button
   if (...)
   {
       node.removeAction(withKey:"moving")
   } 
   ...
}
override func touchesEnded(...)
{
   ...
   node.removeAction(withKey:"moving")
   ...
}
override func touchesCancelled(...)
{
   ...
   node.removeAction(withKey:"moving")
   ...
}

您可以创建某种重复步骤,该步骤从
触摸开始
开始,到
触摸结束
、在
触摸取消
或将触摸移出节点时结束 通过检查
touchesMoved

override func touchesBegan(...)
{
   ...
   let moveAction = SKAction.repeatForever(SKAction.move(by:CGPoint(x:x,y:y)))
   node.run(moveAction,forKey:"moving")
   ...
}
override func touchesMoved(...)
{
   ...
   //add a check to see if if touch.position is not inside the button
   if (...)
   {
       node.removeAction(withKey:"moving")
   } 
   ...
}
override func touchesEnded(...)
{
   ...
   node.removeAction(withKey:"moving")
   ...
}
override func touchesCancelled(...)
{
   ...
   node.removeAction(withKey:"moving")
   ...
}

泰!你帮帮我!泰!你帮帮我!