gpt4 book ai didi

swift - 我怎样才能让两个球员在触球时都移动?

转载 作者:行者123 更新时间:2023-11-30 13:06:20 26 4
gpt4 key购买 nike

我正在制作这个游戏,你应该与另一个人玩躲避球。问题是当我触摸 paddlei 时,我无法让 paddlei 移动。当我触摸桨时,它会移动,但它也会移动 paddlei。我可以做什么或改变什么?

override func touchesBegan(touches: Set<UITouch>, withEvent event: UIEvent?) {
let touch = touches.first
let touchLocation = touch!.locationInNode(self)


let touchi = touches.first
let touchLocationi = touchi!.locationInNode(self)
if let body = physicsWorld.bodyAtPoint(touchLocation) {
if body.node!.name == PaddleCategoryName {
print("Began touch on paddle")
isFingerOnPaddle = true
}
}
if let otherBody = physicsWorld.bodyAtPoint(touchLocationi) {
if otherBody.node!.name == PaddleyName {
print("EL otro toco")
isFingerOnPaddlei = true
}
}
}
override func touchesEnded(touches: Set<UITouch>, withEvent event: UIEvent?) {
isFingerOnPaddle = false
isFingerOnPaddlei = false
}

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

if isFingerOnPaddle {
// 2
let touch = touches.first
let touchLocation = touch!.locationInNode(self)
let previousLocation = touch!.previousLocationInNode(self)
// 3
let paddle = childNodeWithName(PaddleCategoryName) as! SKSpriteNode
// 4
var paddleY = paddle.position.y + (touchLocation.y - previousLocation.y)
var paddleX = paddle.position.x + (touchLocation.x - previousLocation.x)
// 5
paddleY = max(paddleY, paddle.size.width/2)
paddleY = min(paddleY, size.height - paddle.size.height/2)
paddleX = max(paddleX, paddle.size.height/2)
paddleX = min(paddleX, size.height - paddle.size.width/2)
// 6
paddle.position = CGPoint(x: paddleX, y: paddleY)

if isFingerOnPaddlei {

let paddlei = childNodeWithName(PaddleyName) as! SKSpriteNode


// 4
var paddleS = paddlei.position.y + (touchLocation.y - previousLocation.y)
var paddleU = paddlei.position.x + (touchLocation.x - previousLocation.x)
// 5
paddleS = max(paddleS, paddlei.size.width / 2)
paddleS = min(paddleS, size.height - paddlei.size.height / 2)
paddleU = max(paddleU, paddlei.size.height / 2)
paddleU = min(paddleU, size.height - paddlei.size.width / 2)
// 6
paddlei.position = CGPoint(x: paddleU, y: paddleS)

}




}


}

}

最佳答案

if isFingerOnPaddle 位于 if 语句中,声明 if isFingerOnPaddle。第二个 if 语句永远不会被调用,因为它是嵌套的,并且两者永远不应该同时为 true。

关于swift - 我怎样才能让两个球员在触球时都移动?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39313225/

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