physicsWorld.bodyAlongRayStart() creating phantom println (reads 'Chance') - override println function?
我在写的游戏中使用了sprite工具包的内置物理引擎。为了检查字符是否在地面上,我使用
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 | 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 } |
这个代码在场景的
如果场景中只有一个角色,那就不太麻烦了,但我很快就会添加敌人(他们以相同的方式工作,但在处理他们的移动时会有不同的功能),所有这些
是否有可靠的方法可以覆盖标准的
1 2 3 4 5 | func println(object: Any) { #if DEBUG Swift.println(object) #endif } |
号
如果是这样,我应该把它放在我的项目中的什么地方?它目前在
我把这个bug提交给了苹果。他们告诉我它在Xcode的下一个版本中被修复了。如果它真的让你心烦,你可以下载Xcode6.3测试版。