首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
MCP广场
社区首页 >问答首页 >如何加快物体的运动速度?

如何加快物体的运动速度?
EN

Stack Overflow用户
提问于 2015-12-21 16:57:52
回答 1查看 155关注 0票数 1

在手指的场景中,你可以移动物体。但是,如果你只是加快手指在屏幕上的移动-物体仍然在位置。有可能加速它的运动速度吗?持续时间已设置为0。

代码语言:javascript
运行
复制
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)
    }
}
EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2015-12-21 18:31:40

你的问题不是速度,你的问题是你在屏幕上移动得太快,以至于你的触摸不再识别它下面的一个节点,因为这个节点实际上不在它下面。如何处理此问题是在touch begin事件上,您检查节点,并将此节点分配给变量。然后,在“触摸移动”事件中,更新新变量。最后在触摸端,清除变量。注意,您需要处理多点触摸之类的代码。

代码语言:javascript
运行
复制
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)

}
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/34400756

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档