PhysicsBody covers half of sprite

34 views Asked by At

PhysicsBody added only to half of a sprite

enter image description here

I have add a sprite to a GameScene and set a Body type in Physics Definitions to Alpha mask.

Then I want to check if I've clicked on physics body or not. But, it shows yes only when I click on green area.

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

There are 0 answers