gpt4 book ai didi

swift - 我怎样才能改变我的程序,让这个对象只对一次触摸使用react?

转载 作者:行者123 更新时间:2023-11-28 06:41:51 26 4
gpt4 key购买 nike

我正在制作篮球比赛。我的问题是当我射球时,我可以再次在半空中触球,这是我不想要的。一旦用户射出球,我不希望触摸产生影响。这是我的代码:

override func touchesBegan(touches: Set<UITouch>, withEvent event: UIEvent?
{
touching = false
for touch: AnyObject in touches {
let location = touch.locationInNode(self)
if ball.frame.contains(location){
touchingPoint = location
touching = true
}
}
}


override func touchesMoved(touches: Set<UITouch>, withEvent event: UIEvent?) {
for touch: AnyObject in touches {
let location = touch.locationInNode(self)
touchingPoint = location
}
}


override func touchesEnded(touches: Set<UITouch>, withEvent event: UIEvent?) {
if touching{
let dt:CGFloat = 8.25/29.5
let distance = CGVector(dx: touchingPoint.x-ball.position.x, dy: touchingPoint.y-ball.position.y)
let velocity = CGVector(dx: distance.dx/dt, dy: distance.dy/dt)
ball.physicsBody!.velocity=velocity
}
}

我可以在我的程序中添加什么,以便在球被射出后触摸不会产生任何影响?

最佳答案

射完球后禁用用户交互

ball.userInteractionEnabled = false

然后在您希望他们能够触摸它时再次启用它

关于swift - 我怎样才能改变我的程序,让这个对象只对一次触摸使用react?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37755190/

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