PhysicsBody仅添加到精灵的一半
我已将一个精灵添加到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")
}
}
}