问题
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