I have a Box2D world which works great. I'm using it in a pretty simple game where the user tilts the device to push bodies around the screen racking up points when a certain body collides with another.
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.
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.
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.
Here is the code where the menu controller gets loaded:
And here is where the game's view controller gets loaded by the app delegate in application didFinishLaunchingWithOptions:
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:
I'd be grateful for any assistance or ideas that anyone might have.
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.
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.
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.
Here is the code where the menu controller gets loaded:
Code: Select all
//unhide the navbar for the next screen
[self.navigationController setNavigationBarHidden:NO];
MenuViewController *mvc = [[MenuViewController alloc]init];
[self.navigationController pushViewController:mvc animated:YES];
[mvc release];And here is where the game's view controller gets loaded by the app delegate in application didFinishLaunchingWithOptions:
Code: Select all
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];
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:
Code: Select all
b2PolygonShape dynamicBox;
dynamicBox.SetAsBox(boxDimensions.x, boxDimensions.y);
...
b2FixtureDef fixtureDef;
fixtureDef.shape = &dynamicBox;
fixtureDef.density = 3.0f;
fixtureDef.friction = 0.3f;
fixtureDef.restitution = 0.5f;
...
I'd be grateful for any assistance or ideas that anyone might have.