Note that there are some explanatory texts on larger screens.

plurals
  1. POBox2D Rigid Bodies Distorted When Loading Another View
    primarykey
    data
    text
    <p>I have a Box2D world which works great. I'm using it in a simple iOS game where the user tilts the device to push bodies around the screen racking up points when a certain body collides with another.</p> <p>It was working fine when it was buried a couple layers deep in my app in a test controller. I invoked it from a button on my menu screen and a button on the game screen would return to the menu just fine via popToViewController. But once I saw how great it worked I realized that I wanted the game to be the first screen a user sees (after the default loading image). So now the app loads the world and the game is on right off the bat without any problems.</p> <p>Until the user taps the menu button to get to the menu screen - another view controller. The menu controller loads fine and everything works there as expected. BUT when one taps the back button to return to the game/world the images/bodies are distorted. The distortion varies depending on how they happened to be rotated when the menu controller got pushed onto the navigation stack. Sometimes they are enlarged and sometimes smooshed.</p> <p>I did try pausing the world (by not calling Step) when loading the menu controller, but that did not help with the image distortion problem.</p> <p>Here is the code where the menu controller gets loaded:</p> <pre><code> //unhide the navbar for the next screen [self.navigationController setNavigationBarHidden:NO]; MenuViewController *mvc = [[MenuViewController alloc]init]; [self.navigationController pushViewController:mvc animated:YES]; [mvc release]; </code></pre> <p>And here is where the game's view controller gets loaded by the app delegate in application didFinishLaunchingWithOptions:</p> <pre><code> B2DViewController *b2dvc = [[B2DViewController alloc]init]; UINavigationController *navcon = [[UINavigationController alloc] init]; [navcon setNavigationBarHidden:YES]; [navcon pushViewController:b2dvc animated:NO]; [window addSubview:navcon.view]; [b2dvc release]; [window makeKeyAndVisible]; </code></pre> <p>The images come in via a xib. One is button and one is an imageView. Both are added to dynamic bodies which are configured thusly:</p> <pre><code> b2PolygonShape dynamicBox; dynamicBox.SetAsBox(boxDimensions.x, boxDimensions.y); ... b2FixtureDef fixtureDef; fixtureDef.shape = &amp;dynamicBox; fixtureDef.density = 3.0f; fixtureDef.friction = 0.3f; fixtureDef.restitution = 0.5f; ... </code></pre> <p>I tried hiding all the subviews but, as you might suspect, that only hid them from view, not from the forces of distortion. I also turned off all the stretching and resizing stuff in IB, to no avail (I was just guessing). </p> <p>I'd be grateful for any assistance or ideas that anyone might have.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload