0
votes

I have a few images that can detect when they get touched right now I am using

plane.physicsBody = SKPhysicsBody(circleOfRadius: plane.frame.height / 2)

but I need it so it is the boarder of the image not a circle or rectangle.

1
What do you want it to be?Knight0fDragon
i want it to fix the size of the image assigned to it, it is a complex 2d object that a circle and rect does not fit its exact size. So i need to make the physicsbody fit the exact size of the image @Knight0fDragonshane
then use SKPhysicsBody(texture:), if your sprite consists of multiple nodes, create a texture out of it by view.textureFromNodeKnight0fDragon
@Knight0fDragon Put that as a formal answer. That's definitely the correct answer as long as his picture uses clear pixelsNik
nah the question should just be deletedKnight0fDragon

1 Answers

1
votes

We have a plane and you want a physical body. Your first approach is circleOfRadius (the physical representation is a circle with a given radius). You can use another shape, such a rectangle:

plane.physicsBody = SKPhysicsBody(rectangleOfSize: CGSizeMake(100, height: 100))  

As explained in the comments you can also use the shape of a sprite (texture) to create the shape of the physics body:

plane.physicsBody = SKPhysicsBody(texure: plane.texture!, size: plane.size)

But a good way to choose it's this: if you want your game to run smootly on many different devices, don't make sure the physics calculations become too complicated. In other words if you have many object around your plane with physical behavior moving around and colliding with each other, you may choose to use simplified shapes to deal with the physics more efficiently, especially if a shape already looks a lot like a rectangle or a circle.