When objects come into contact, a text appears in me, is it possible to make it appear in the place where the objects touched? https://yadi.sk/d/Inp2b0wptcKEv
2 answers
You have a contact object in didBeginContact
, which has a contactPoint property. This is the point where the collision occurred, where you need to put your UILabel.
One caveat that must be taken into account: the 0-0 point of the physical world falls on the lower left corner, and UILabel counts the coordinates from the upper left, to get the coordinate of the label's vertical position, you will need to remove the physical coordinate from the size of the scene.
UPDATE: it turns out your scene does not match the size of the screen - the screen in points 320x568, and the scene 640x1136
A few clarifications:
that's how I figured out where to put the label
if ((contactBody1.categoryBitMask == 2) && (contactBody2.categoryBitMask == PhysicsCategory.Ball)) { var reverse = CGPointMake(contact.contactPoint.x/2, contact.contactPoint.y/2) reverse.y = self.view!.bounds.size.height - reverse.y PX.center = reverse self.view?.addSubview(PX) }
do not forget to put the text label in the center
PX.textAlignment = .Center
and if you want the scene to look normal on any device
self.scene?.size = CGSize(width: self.view!.frame.size.width*2, height: self.view!.frame.size.height*2)
- Thank you very much for the detailed response) - Leci 5:38 pm
You can read the contact point from contact.contactPoint
and use this data to indicate the coordinates of your UILabel