0

I'm new to Box2D, and working on a first project using EaselJS along with Box2DWeb. I'm hoping to have the standard static shapes that comprise the walls and floor of the world to move/update along with the browser window when it's resized. I'm using SetPosition to accomplish it, which is called with each execution of Easel's tick method - and it's almost working. When the browser is made larger, everything works as expected - the floor lowers and the dynamic objects fall accordingly.

However when the browser is made smaller, the bodies in the scene will seem to often fall right through the static floor body and disappear. It seems to occur only if the resize is significant enough to cause the dynamic body in question to briefly descend out of window view (for example, fully below the browser pane when decreasing the height). If I resize the browser reasonably slowly however... strangely enough it works.

I can think of no good solution to my problem, and I have not had any luck finding an example of the behavior on the web. Can it be done? Very grateful for any assistance.

Lee:

Absolutely - thanks so much for the reply. This is a backbone.js project. The example can be seen here:

http://kensonger.com/b2dweb/

The basic window resize listener is at the bottom of the file here:

/b2dweb/js/routers/Main.js

...it references app.box2d. That's a backbone view here:

/b2dweb/js/views/Box2DView.js

The 'onStageResize' method is positioning the world boundaries. The update method at the bottom of this class is called 45/sec via the tick method in /b2dweb/js/routers/Main.js.

A zip of the entire effort is zipped here:

http://kensonger.com/b2dweb/box2d_experiment.zip

You can see the box2d/easel objects passing through the floor if you quickly size the browser pane upward, and then downward again quickly. If you don't resize downward, the objects just fall through and vanish. If you do however, the floor passes through once more and catches the falling objects.

Again, thanks a million for any insights - greatly appreciated.

gomper
  • 1
  • 2
  • show some of your code maybe? –  Feb 20 '13 at 04:25
  • Thanks for the speedy reply Lee! I have edited my post above to provide code examples. The only relevant bits are in Main.js and Box2DView.js - and if anything doesn't make sense, just let me know. – gomper Feb 20 '13 at 08:55

1 Answers1

0

Well hey, it looks like I've just gotten it working now - I made each of the world boundaries the equivalent of 1000 pixels thick and for each element I call SetActive(true) as it's instantiated. I haven't determined which change did the trick, but I think it's that SetActive call.

http://kensonger.com/b2dweb/

If someone knows a better solution, please feel free to post it and I'll try it out...

gomper
  • 1
  • 2