我在GameScene中获得了英雄的SKSpriteNode。我实现了两个按钮(向上和向下)。我需要我的英雄的SKSpriteNode通过按钮触摸上下移动。但我只看到touchesMoved和touchesEnded方法。我需要一些关于touchesBegan的东西(当我点击它时感觉按钮点击。)
答案 0 :(得分:0)
您创建某种重复步骤,从touchesBegan
开始,到touchesEnded
结束,touchesCancelled
或触摸从节点移开时
选中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")
...
}