Reputation: 11
Does anyone have any guidance how to create a SpriteKit object that looks like a circle with circular physics properties? I've considered using SKShapeNode, yet after reading comments in documentation like this one "the SKSpriteNode class offers higher performance than this class, so use shape nodes sparingly" here https://developer.apple.com/documentation/spritekit/skshapenode, I'm reluctant to use SKShapeNode.
I have code to create an SKSpriteNode from image that makes it look like a circle...
sprite = SKSpriteNode(imageNamed:spriteImage)
...and I've applied a circular physics body...
sprite.physicsBody = SKPhysicsBody(circleOfRadius: (width / 2))
I've set properties such as allowrotation, affectedbygravity and isDynamic to true in the physics body...
physics = sprite.physicsBody
physics.affectedByGravity = true
physics.allowsRotation = true
physics.isDynamic = true
The circle SKSpriteNode still behaves like a square. Instead of rolling like a wheel, the object flops like a square.
Upvotes: 0
Views: 677
Reputation: 11
cc was right. The original physics body was set to a circle, then at some point in the code the physics body was changed back into a square. I fixed that part of the code and it is working now. Thanks!
Upvotes: 0