Quick Links: Download Gideros Studio | Gideros Documentation | Gideros Development Center | Gideros community chat | DONATE
Box2d Resuming Game — Gideros Forum

Box2d Resuming Game

antixantix Member
edited July 2016 in General questions
I'm messing about with Box2d and when I suspend and then resume the application, the physics objects are re positioned on the screen in seemingly random places.

How does one go about managing Box2d objects when the application is suspended and then resumed.

Does anyone else have experience with this phenomenon?

Comments

  • n1cken1cke Maintainer
    Accepted Answer
    There is no simple way to save/load box2d world state. I suggest to iterate over each body and get all their box2d properties you use in your game and then use box2d setters to restore them back.

    Likes: antix

    +1 -1 (+1 / -0 )Share on Facebook
  • totebototebo Member
    @antix I haven't seen this problem. For me the Box2D world stays the same after the app has been suspended and resumed. Does it happen because the device orientation has changed, so everything is rotated 90 degrees? Or is it literally random?
    My Gideros games: www.totebo.com
  • antixantix Member
    Thanks guys. I think I'll just flag Box2d and code it by hand :)

    I think n1cke has a good solution as I think you can catch an event when the app is paused.

    @totebo, no it always happens. My physics objects are moving down the screen and their y positions are drastically altered on resume. It might be because I am actually setting their positions instead of applying impulses and stuff. For now it doesn't matter since this is a quick project that really doesn't need actual physics. I'll be thinking about this a lot later when I make something that requires physics :)
  • totebototebo Member
    Okay mate, well let us know if you bump into this one again. Should be fixable.

    Likes: antix

    My Gideros games: www.totebo.com
    +1 -1 (+1 / -0 )Share on Facebook
  • antixantix Member
    No worries, I am going to use bump.lua for most collisions and a special function for the paddle vs ball :)

    Likes: totebo

    +1 -1 (+1 / -0 )Share on Facebook
  • john26john26 Maintainer
    I've never noticed this problem either. Is it happening for all exports or any in particular. Sounds like the app is still executing ENTER_FRAME events even while suspended. You could check this by making sure you don't execute world:step when suspended. Then the b2d objects cannot move.

    If you only just noticed this bug, try using an older version of Gideros. Might be a recent reversion.

    Likes: antix

    +1 -1 (+1 / -0 )Share on Facebook
  • antixantix Member
    @john26 I'm not sure if it's happening on export as I have only noticed this behavior in the desktop player (I've not tested my game on any devices yet).

    Anyway I've used Bump.lua for ball/wall/block collision and some custom code for ball/paddle collision. You just can't get a decent pongy simulation with a physics engine :)
Sign In or Register to comment.