Designing physical bodies other than circles

I am making my first game with SpriteKit and the physical bodies of enemy aliens (subclass SKSpriteNode), which I used:

self.physicsBody = SKPhysicsBody(circleOfRadius: self.size.width/2)

this worked as most aliens are round in shape. However, if I had ellipses or square aliens, what would be the best method for designing their physical bodies? I tried this for a square shape:

let squarePath = UIBezierPath(rect: CGRect(x: -64, y: -64, width: 128, height: 128))
self.physicsBody = SKPhysicsBody(polygonFromPath: squarePath.CGPath)

but I don’t know if this is the most effective, nor do I know how to accurately create ellipses. Any suggestions would be great!

+4
source share
2 answers

- , SKPhysicsBody (rectangleOf: CGSize (width: 100, height: 100))

: , : http://insyncapp.net/SKPhysicsBodyPathGenerator.html

. , , .

+1

SpriteKit !

, PhysicsBody, SpriteKit . SpriteKit , ( / ) , , , .

,

let croc = SKSpriteNode(imageNamed: "croc_walk01")
croc.position = CGPoint(x: frame.midX, y: frame.midY)
addChild(croc)

enter image description here

PhysicalBody

croc.physicsBody = SKPhysicsBody(texture: croc.texture!, size: croc.texture!.size())

SpriteKit PhysBody.

enter image description here

? . ,

croc.hidden = true 

enter image description here

+2

Source: https://habr.com/ru/post/1651180/


All Articles