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

时间:2015-02-26 09:39:25

标签: ios swift sprite-kit println skphysicsworld

我在写作的游戏中使用了Sprite Kit的内置物理引擎。为了检查角色是否在地面上,我使用bodyAlongRayStart() SKScene的{​​{1}}功能来检查角色下方的尸体。角色的左下角和右下角(此函数属于角色的类):

physicsWorld

此代码在场景的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() ...)并且它工作正常!然而,令人恼火的是,Swift无限智慧决定每次检测到沿着光线的身体时都会向控制台打印didSimulatePhysics()

在场景中只有一个角色,这不是太麻烦,但我很快就会加入敌人(他们的工作方式大致相同,但会有不同的功能来处理他们的动作并且所有这些Chance调用将使模拟器向下减速。我无法看到一种压制这种情况的方法;这个电话来自我无法改变的班级图书馆。

是否有可靠的方式来覆盖标准println()功能?像这样:

println()

如果是这样,我的项目应该放在哪里?它目前在func println(object: Any) { #if DEBUG Swift.println(object) #endif } 但其他库(以及AppDelegate.swift函数)仍在打印到控制台,即使我更改了标志...

1 个答案:

答案 0 :(得分:3)

我已将此错误提交给Apple。他们告诉我它已经在Xcode的下一个版本中修复了。如果它真的让你烦恼,你可以下载Xcode 6.3 beta。