简体   繁体   English

touchesMoved:如何知道触摸何时结束?

[英]touchesMoved: How to know when the touch ended?

I have a ball that I want to move around (Spritekit) and I want to set a velocity so when the player move the ball then he moves his finger from the screen the ball will move and it will have it's own velocity depinding on some calculations 我有一个要移动的球(Spritekit),我想设置一个速度,这样当玩家移动球然后将手指从屏幕上移开时,球将移动,并且在某些计算中球的速度会降低

the question : this is my code , how can I know when the player is moving his finger from the screen ?! 问题:这是我的代码,如何知道玩家何时将手指从屏幕上移开?

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

        if let touch = touches.first as? UITouch{
            var location = touch.locationInNode(self)
            ball6.position = location
        }

Use this method: 使用此方法:

override func touchesEnded(touches: NSSet, withEvent event: UIEvent) {
    //your code
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM