I have this object that has a physical element created from a path.
The entire area of the scene (= full screen) in itself is the boundary from where this object should not disappear.
This scene boundary is defined
self.physicsBody = [SKPhysicsBody bodyWithEdgeLoopFromRect:self.frame];
Everything works almost as expected. The object collides and bounces around the edges and is limited by them most of the time, but if you insist several times by shooting the object with a high momentum to the edge, the object will ultimately not respect the edge and run away, which is probably another SpriteKit error.
The init object class is as follows:
self.physicsBody.dynamic = YES;
CGFloat offsetX = self.frame.size.width/2.0f;
CGFloat offsetY = self.frame.size.height/2.0f;
CGMutablePathRef path = CGPathCreateMutable();
CGPathMoveToPoint(path, NULL, 60 - offsetX, 79 - offsetY);
CGPathAddLineToPoint(path, NULL, 96 - offsetX, 69 - offsetY);
CGPathAddLineToPoint(path, NULL, 124 - offsetX, 44 - offsetY);
CGPathAddLineToPoint(path, NULL, 120 - offsetX, 23 - offsetY);
CGPathAddLineToPoint(path, NULL, 85 - offsetX, 0 - offsetY);
CGPathAddLineToPoint(path, NULL, 62 - offsetX, 3 - offsetY);
CGPathAddLineToPoint(path, NULL, 37 - offsetX, 19 - offsetY);
CGPathAddLineToPoint(path, NULL, 12 - offsetX, 29 - offsetY);
CGPathAddLineToPoint(path, NULL, 3 - offsetX, 39 - offsetY);
CGPathAddLineToPoint(path, NULL, 7 - offsetX, 58 - offsetY);
CGPathAddLineToPoint(path, NULL, 27 - offsetX, 46 - offsetY);
CGPathAddLineToPoint(path, NULL, 36 - offsetX, 61 - offsetY);
CGPathCloseSubpath(path);
self.physicsBody = [SKPhysicsBody bodyWithPolygonFromPath:path];
self.physicsBody.restitution = 0.0f;
self.physicsBody.usesPreciseCollisionDetection = YES;
What measures can I take to detect this and prevent the object from leaving the screen?
thank.