0
\$\begingroup\$

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.

\$\endgroup\$
1
\$\begingroup\$

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.

\$\endgroup\$
  • \$\begingroup\$ I'll have a few dozens of dynamic objects that are going to bounce off the world edges (except top side). \$\endgroup\$ – src091 Jan 23 '15 at 15:16
  • \$\begingroup\$ 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 \$\endgroup\$ – dimitris93 Jan 23 '15 at 15:24
  • 1
    \$\begingroup\$ Alrite, rectangles then. \$\endgroup\$ – src091 Jan 23 '15 at 15:35

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.