Defining physicsbody for a curved object

跟風遠走 提交于 2021-01-29 15:20:36

问题


How can I define the physics body of an curved or not rectangle object

I know for a rectangle I use ( rectangle of : width,height)

And for a circle I use (circle of radius: )

But how can I do this for a different object like this one


回答1:


You can use a CGPath like this:

let path = CGMutablePath()
path.addLine(to: CGPoint(x: 10, y: 10))
path.addArc(center: CGPoint(x: 20, y: 20), radius: 50, startAngle: 20, endAngle: 60, clockwise: true)
node?.physicsBody = SKPhysicsBody(edgeLoopFrom: path)

You can show the bodies of SKView with:

view.showsPhysics = true

The complete example are here: GameScene.swift



来源:https://stackoverflow.com/questions/65145181/defining-physicsbody-for-a-curved-object

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