触摸与圆形精灵超大的接触

时间:2016-11-27 11:44:06

标签: ios swift sprite-kit

我有一个简单的spritekit项目,其中我注意到我的精灵注册的接触点发生在圆形物理体之外。

在这里展示:

https://gfycat.com/DentalBriskAfricangroundhornbill

使用showPhysics:http://i.imgur.com/F4BcXhb.png

产生圆圈的对象的代码:

    func spawnObject() {
    object = SKSpriteNode(imageNamed: "Oval")
    //object.fillColor = SKColor.white
    object.name = "ball"
    object.position = CGPoint(x: 280, y: 520)
    object.physicsBody = SKPhysicsBody(circleOfRadius: object.size.width / 2)
    object.physicsBody!.isDynamic = true
    object.physicsBody!.contactTestBitMask = object.physicsBody!.collisionBitMask
    object.physicsBody?.friction = 0.2
    object.physicsBody?.restitution = 0.2
    object.physicsBody?.mass = 5
    addChild(object)
}

圆圈本身彼此完美互动 - 看起来触摸就是异常值。

非常感谢任何帮助:)

编辑: 触摸代码示例:

 override func touchesBegan(_ touches: Set<UITouch>, with event: UIEvent?) {
        if let touch = touches.first {
            let location = touch.location(in: self)
            let tappedNodes = nodes(at: location)

            for node in tappedNodes {
                if node.name == "ball" {
                    node.alpha = 0.5
                }
            }
        }
    }

0 个答案:

没有答案