How to get SKSpriteNode by physicsBody?

后端 未结 1 1944
孤街浪徒
孤街浪徒 2021-01-16 01:21

I extended SKSpriteNode with my own class to have more functions.

But how can I get this extended node when something \'hits\' this node and didBe

1条回答
  •  执笔经年
    2021-01-16 01:40

    So, here is an example of how you can get the node associated with the physics body.

    var node = SKSpriteNode(imageNamed: "theimage")
    
    node.physicsBody = SKPhysicsBody(circleOfRadius: 6)
    
    var copy = node.physicsBody
    

    Now, I will get the SKNode associated with copy

    var node = copy.node
    

    So, all you have to do is call the property node on the physicsBody. Remember that the node property returns an SKNode, not SKSpriteNode.

    0 讨论(0)
提交回复
热议问题