Swift 通过按钮触摸移动SKSpriteNode
在我的游戏场景中我得到了英雄的斯普林泰诺德。我实现了两个按钮(向上和向下)。我需要我的英雄的斯普林泰诺德通过按键上下移动。但我只看到触控移动和触控移动的方法。我需要一些关于touchsbegind(在我点击按钮时感觉到按钮在点击)的信息。您创建某种重复步骤,从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
开始,到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")
...
}
泰!你帮帮我!泰!你帮帮我!