gpt4 book ai didi

swift - TouchesMoved swift 滞后

转载 作者:可可西里 更新时间:2023-11-01 02:28:03 27 4
gpt4 key购买 nike

我正在使用 SpriteKit 中的 Swift 在 Xcode 6 Beta 6 中编写代码。在代码中,当用户移动手指时,我需要一张图片来跟随手指。 touchesMoved 有效但有小故障。如果我慢慢移动手指,一切都很好。如果我从右向左快速移动手指,那么一切都很好。如果我从左到右快速移动手指,那么图片只会跟随手指几分之一秒。如果我在当前位置点击并按住图片大约半秒钟,那么当我从右到左或从左到右快速移动它时,一切都很好。总之,除非我点击并按住图片大约半秒钟,否则我无法从左到右快速移动图片。有人知道为什么会这样吗?谢谢你的时间。下面是代码。我正在移动 SKSPriteNode follow2

override func touchesMoved(touches: NSSet, withEvent event: UIEvent) {

for touch: AnyObject in touches {

let angle_area_location = touch.locationInNode(self)

if self.nodeAtPoint(angle_area_location) == self.angle_area {

if (angle_area_location.x <= 21) {
angle = 1.55681122463001
distance12 = sqrt((angle_area_location.y - 30) * (angle_area_location.y - 30) + 1)

}

if (angle_area_location.y <= 31) {
angle = 0.0102037274939542
distance12 = sqrt((31 - 30) * (31 - 30) + (angle_area_location.x - 20) * (angle_area_location.x - 20))

}

if (angle_area_location.x > 21) && (angle_area_location.y > 31) {

angle = atan((angle_area_location.y - 30) / (angle_area_location.x - 20))
distance12 = sqrt((angle_area_location.y - 30) * (angle_area_location.y - 30) + (angle_area_location.x - 20) * (angle_area_location.x - 20))

}

if (distance12 <= maxFollow2) && (distance12 >= minFollow2) {

self.cannon.zRotation = angle
self.arc.zRotation = angle

if (angle_area_location.x > 21) || (angle_area_location.y > 31) {
follow2.position = CGPointMake(angle_area_location.x , angle_area_location.y)
}

if(angle_area_location.x <= 21) {

follow2.position = CGPointMake(21 , angle_area_location.y)

}

if (angle_area_location.y <= 31) {

follow2.position = CGPointMake(angle_area_location.x , 31)

}



}
if(distance12 > maxFollow2) {

self.cannon.zRotation = angle
self.arc.zRotation = angle
delta = 290/3
arc.size = CGSizeMake(160 * (1 + delta/20) , 35)
arc.position = CGPointMake(20 - 3 * (delta) * cos(angle) , 30 - 3 * (delta) * sin(angle))
followdist = 360
follow2.position = CGPointMake(angle_area_location.x , angle_area_location.y)
velocity = vmin + (followdist - minFollow2) * (300/(maxFollow2 - minFollow2))

}

if (distance12 < minFollow2) {

self.cannon.zRotation = angle
self.arc.zRotation = angle
arc.size = CGSizeMake(160 , 6.8)
arc.position = CGPointMake(20 , 30)
follow2.position = CGPointMake( minFollow2 * cos(angle) + 20 , minFollow2 * sin(angle) + 30)
followdist = sqrt((follow2.position.y - 30) * (follow2.position.y - 30) + (follow2.position.x - 20) * (follow2.position.x - 20))
velocity = vmin + (followdist - minFollow2) * (300/(maxFollow2 - minFollow2))


}

}

}


}

最佳答案

好的,我发现了故障。我有一个 UISwipeGestureRecognizer,它在我向右滑动时调用一个方法。我停用了它,一切正常。我想在 touchesMoved 上向右滑动和从左向右移动会相互干扰。

关于swift - TouchesMoved swift 滞后,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25655202/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com