PhysicsBody覆盖了精灵的一半

时间:2019-01-18 13:06:32

标签: sprite-kit

PhysicsBody仅添加到精灵的一半

enter image description here

我已将一个精灵添加到GameScene并将“物理定义”中的“身体”类型设置为Alpha遮罩。

然后我要检查是否单击了物理主体。 但是,只有当我单击绿色区域时,它才会显示

override func didMove(to view: SKView) {
    let texture = SKTexture(imageNamed: "walking_walking_2")
    let wallS = SKSpriteNode (texture: texture)
    wallS.physicsBody = SKPhysicsBody(texture: texture, size: texture.size())
    wallS.physicsBody?.isDynamic = false
    self.addChild(wallS)
    view.showsPhysics = true
}

override func touchesBegan (_ touches: Set<UITouch>, with event: UIEvent?) {
    for t in touches {
        touchLocation = t.location(in: self)
        let touchedNode = physicsWorld.body(at: touchLocation!)
        if (touchedNode?.categoryBitMask == 1)
        {
            print("yes")
        } else {
            print ("no")
        }
    }
}

0 个答案:

没有答案