ios - 如何加快物体的运动?

标签 ios swift sprite-kit skaction

在场景中你可以用手指移动物体。但是,如果您只是加快手指在屏幕上的移动速度 - 对象就会保持原位。有没有可能加快它的移动速度?持续时间已设置为 0

override func touchesMoved(touches: Set<UITouch>, withEvent event: UIEvent?) {

    let touch = touches.first
    let touchLocation = touch!.locationInNode(self)
    let node = self.nodeAtPoint(touchLocation)

    if (node.name == "circle") {

        let moveAction = SKAction.moveTo(touchLocation, duration: 0)

        figureUser.runAction(moveAction)
    }
}

最佳答案

你的问题不是速度,你的问题是你在屏幕上移动得太快了,你的触摸不再识别它下面的节点,因为该节点实际上不在它下面。你如何处理这个问题是在触摸开始事件上,你检查一个节点,并将这个节点分配给一个变量。然后在触摸移动事件上,更新新变量。最后在触摸结束时,清除变量。请注意,您需要为诸如多点触控之类的事情处理此代码

var movingNode : SKNode?
override func touchesBegan(touches: Set<UITouch>, withEvent event: UIEvent?)     {

    let touch = touches.first
    let touchLocation = touch!.locationInNode(self)
    let node = self.nodeAtPoint(touchLocation)

    if (node.name == "circle") {
        movingNode = node
        let moveAction = SKAction.moveTo(touchLocation, duration: 0)

        figureUser.runAction(moveAction)
    }
}
override func touchesMoved(touches: Set<UITouch>, withEvent event: UIEvent?)     {

    let touch = touches.first
    let touchLocation = touch!.locationInNode(self)

        let moveAction = SKAction.moveTo(touchLocation, duration: 0)
     //at this point I am lost,  how does node even relate here,  
     //is figureUser suppose to be node?
        figureUser.runAction(moveAction)

}

关于ios - 如何加快物体的运动?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34400756/

相关文章:

ios - 终止应用程序后我没有获取用户当前的运行位置

ios - 无法解析 RFC822 日期

ios - Firebase 在中国的分析

swift - 如何在 Swift 中添加双击手势识别器

ios - 如何以编程方式从 Images.xcassets 加载 .pdf 图像

swift - 如何禁止重写数据(如果存在)

javascript - iPhone : Fast Forward & Rewind using HTML5 <audio> & playbackRate doesn't work?

ios - 如何加载内存中的文件以获得更好的场景转换?

swift - 在 SpriteKit 中显示 Game Center 排行榜

ios - 如何修复 SKEmitterNode 的内存泄漏?