gpt4 book ai didi

ios - physicsWorld.bodyAlongRayStart() 创建幻像 println(读取 'Chance')- 覆盖 println 函数?

转载 作者:可可西里 更新时间:2023-11-01 01:06:19 25 4
gpt4 key购买 nike

我正在编写的游戏中使用 Sprite Kit 的内置物理引擎。为了检查角色是否在地面上,我使用了 SKScenephysicsWorldbodyAlongRayStart() 函数检查角色左下角和右下角下方的物体(此函数属于角色类):

func isInAir(sceneRef:GameScene) -> Bool {
var isInAir:Bool = false

let distance:CGFloat = 32 // how far from the origin we should check

// define where the rays start and end
let bottomLeftRayStart:CGPoint = CGPoint(x: self.position.x - (self.hitbox.size.width/2), y: self.position.y - (self.hitbox.size.height/2))
let bottomLeftRayEnd:CGPoint = CGPoint(x: self.position.x - (self.hitbox.size.width/2), y: (self.position.y - (self.hitbox.size.height/2) - distance))
let bottomRightRayStart:CGPoint = CGPoint(x: self.position.x + (self.hitbox.size.width/2), y: self.position.y - (self.hitbox.size.height/2))
let bottomRightRayEnd:CGPoint = CGPoint(x: self.position.x + (self.hitbox.size.width/2), y: (self.position.y - (self.hitbox.size.height/2) - distance))

// Are there any bodies along the lines?
var bottomLeftBody:SKPhysicsBody! = sceneRef.physicsWorld.bodyAlongRayStart(bottomLeftRayStart, end:bottomLeftRayEnd)
var bottomRightBody:SKPhysicsBody! = sceneRef.physicsWorld.bodyAlongRayStart(bottomRightRayStart, end:bottomRightRayEnd)

// no bodies found
if bottomLeftBody == nil && bottomRightBody == nil {
isInAir = true
} else {
// if one of the rays finds a wall (floor) or slope, we're not in the air
if (bottomLeftBody != nil && (bottomLeftBody!.categoryBitMask == _entityType.wall.rawValue || bottomLeftBody!.categoryBitMask == _entityType.slope.rawValue)) || (bottomRightBody != nil && (bottomRightBody.categoryBitMask == _entityType.wall.rawValue || bottomRightBody!.categoryBitMask == _entityType.slope.rawValue)) {
isInAir = false
}
}
return isInAir
}

此代码在场景的 update() 函数中调用(尽管我可能应该将其移至 didSimulatePhysics()...)并且它工作正常!然而,令人恼火的是,Swift 以其无限的智慧决定在每次沿射线检测到物体时将 Chance 打印到控制台。

场景中只有一个角色并不太麻烦,但我很快就会添加敌人(他们的工作方式大致相同,但处理他们的 Action 会有不同的功能)和所有这些 println() 调用会减慢模拟器的速度。我看不出有什么办法可以抑制它;调用来 self 无法更改的类库。

是否有一种可靠的方法来全局覆盖标准 println() 函数?像这样:

func println(object: Any) {
#if DEBUG
Swift.println(object)
#endif
}

如果是这样,我应该把它放在项目的什么地方?它目前在 AppDelegate.swift 中,但即使我更改标志,其他库(和 bodyAlongRayStart() 函数)仍在打印到控制台...

最佳答案

我已将此错误提交给 Apple。他们告诉我它已在下一版本的 Xcode 中修复。如果它真的困扰您,您可以下载 Xcode 6.3 beta。

关于ios - physicsWorld.bodyAlongRayStart() 创建幻像 println(读取 'Chance')- 覆盖 println 函数?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28738880/

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