How to get SKSpriteNode by physicsBody?

▼魔方 西西 提交于 2019-12-01 12:18:19

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.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!