# Set world boundaries in box2d

So far I've seen the only way to set boundaries on box2d world which is to create rectangular shapes and place them at the edges of the screen, is there any other way? Perhaps I can set boundaries with some formula instead of shapes?

Why I'm asking: suppose my "world" looks like a rectangular box without top constraint so any object is ultimately constrained on left, right and bottom sides but can appear infinitely high.

If in your game there are only a couple of objects that could possibly go outside of your game limits, you don't have to add rectangles to set the boundaries in your game unless it somehow makes your code cleaner in your case. Efficiency-wise I guess the old fashioned if (object1.Position.X < 0) qualifies as the left boundary in your game. If you have many moving objects though, I guess you would have to go with rectangles.
• if those dozens of dynamic objects are not objects of the same class (for example bouncing balls), so you can't add the 3 ifs (for the left-right-bottom boundary) in your ball.Update() function in your ball class, then i guess it would not be a very pretty solution – dimitris93 Jan 23 '15 at 15:24