gpt4 book ai didi

swift - 如何检查一个sknode是否接触了另一个sknode

转载 作者:行者123 更新时间:2023-11-30 11:46:56 25 4
gpt4 key购买 nike

我正在制作一款游戏,其中一个 SKSpriteNode 需要触摸另一个 SKSpriteNode 才能击败对手。

 func intersects(node: SKSpriteNode) -> Bool {
if ball.intersects(ygB) == true{
ylicount = ylicount - 1
yourlivescount.text = "\(ylicount)"
if ylicount == 0{
self.view!.window!.rootViewController!.performSegue(withIdentifier: "GameOverViewController", sender: self)
}
}else if ball.intersects(egB) == true{
elicount = elicount - 1;

enemylivescount.text = "\(elicount)"
if elicount == 0{
levelcount += 1
lccalc += 1
ball.physicsBody?.restitution = (ball.physicsBody?.restitution)! - 0.000065416191
ep.run(SKAction.moveTo(x: ball.position.x, duration: 0.5 - (lccalc * 0.00001916151134)))
elicount += 3
ball.position.x = 0
ball.position.y = 0
}

}

本质上,有两个目标:yg和eg。 ygB是yg周围不可见的SKNode,egB对于eg来说是一样的。如果球与 ygB 或 egB 相交,代码应该执行相应的操作

我做错了什么?

最佳答案

为您想要相互接触的两个节点提供 SKPhyiscs 主体 .dynamic。其次,使用位掩码设置冲突检测。 https://developer.apple.com/documentation/spritekit/skphysicsbody https://developer.apple.com/documentation/spritekit/skphysicscontactdelegate

关于swift - 如何检查一个sknode是否接触了另一个sknode,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48729344/

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