2

If I define an open UIBezierPath and set it as a collision boundary:

_containerPath = [UIBezierPath bezierPathWithArcCenter:center
                                                radius:radius
                                            startAngle:M_PI
                                              endAngle:0
                                             clockwise:NO];

[_collisionBehavior addBoundaryWithIdentifier:@"containerBoundary" forPath:_containerPath];                                                     

and then turn gravity on, objects that are released inside the "bowl" respect the lower boundary, but objects released from above the bowl come to rest on the supposedly non-existent side. Is this expected behavior?

falling rect

In the picture, the red rectangle was dropped from above; the reference view for the dynamic animator is the light gray rect. It fell from above and stopped at the invisible line.

I've confirmed that if you flip the bezier path over, the red rect does in fact respect the curved boundary; I've also tried this using an open (two-sided) triangle instead of curved path - same result.

Phil Mitchell
  • 699
  • 8
  • 25

1 Answers1

1

The behavior you're seeing seems to be the same as what you see for fill with a bezier path. If you draw a "V" and fill it, it behaves as if it were a closed path. With the collision boundaries, you can make an open "V" by adding two lines with addBoundaryWithIdentifier:fromPoint:toPoint:. I don't know it there's any other way around the problem. For your half circle, I presume you could approximate it with a series of straight lines added with the method above. I've approximated circles before using 50 to 100 lines that look very close to what you get with BezierPathWithOvalInRect. I don't know if this creates a serious burden on the system when used as a collision boundary.

rdelmar
  • 103,982
  • 12
  • 207
  • 218
  • 1
    I tried this with 20 sides (for the half circle), and it definitely did have an effect on performance in a test where I had many small views bouncing around. – rdelmar Mar 14 '15 at 05:26
  • great idea, though! thanks for the suggestion. I'm looking into SpriteKit right now and it's interesting to note that SKPhysicsBody specifically supports two distinct types: volumes and edges. I suspect that SK is the way for me to go ... – Phil Mitchell Mar 14 '15 at 05:38