Physics and Storyboard

What’s the best way to work with physics and storyboard?

I am switching between several scenes with storyboard that each use physics. What’s the best approach.

Is it best to create an instance of physics in each scene. Or, create a global instance or add instance to the storyboard object?

So far I have been creating a local copy of physics in each scene. I start and stop physics with the enterScene and exitScene event handlers. This works but sometimes the scene transitions stop early. [import]uid: 98652 topic_id: 22712 reply_id: 322712[/import]

You may try global and simply adjust gravity on a scene-by-scene basis; I’d be interested to hear if that fixed the transition issue. [import]uid: 52491 topic_id: 22712 reply_id: 90660[/import]

Using physics as a global variable doesn’t seem to help.

Imagine there are two scenes in storyboard. Each with some falling crates. The transition between each scene is a slide left and slide right. The transition works but sometimes it slides too far or not far enough.

Imagine you’re seeing the falling boxes in scene 1. You click a button to got to scene 2 and the first scene slides to the left while scene 2 slides in from the right. The problem is that scene 2 slides too far to the right. Ending halfway off the left side of the screen.

I’m wondering if the problem could be related to using the scene group as a container for the physics elements. I’m adding them to the scene’s group at this point. [import]uid: 98652 topic_id: 22712 reply_id: 90666[/import]

Adding a subgroup didn’t seem to change much.

The problem seems to be intermittent. Some times the transitions are fine and other times the transitions are off by a small amount and other times the transitions are way off.

I’m starting to suspect the problem might occur if the object has moved outside the boundaries of the screen to the right when the transition occurs. Storyboard might measure the width of the scene by getting of the scene group. With the physics body outside screen storyboard might see the width as wider and slide the whole thing further to the left. [import]uid: 98652 topic_id: 22712 reply_id: 90668[/import]

Changing the transition to Fade seems to fix the problem. Which makes me think that placing objects outside the screen area effects the transition slide left and can effect the slide right.

One more thing, while we’re on the subject of storyboard and physics together. In each of my scene.lua files I’ve declared physics as a local variable, with:

local physics

I switch on the hybrid view and I notice that physics objects from the NOT visible scene still exist in the currently visible scene. I See the hybrid outline and the objects cause collisions. Though I don’t see the image associated with the object.

It seems that physics must act as a singleton. Where only one instance is created with any call to:

require(“physics”) [import]uid: 98652 topic_id: 22712 reply_id: 90669[/import]

This sounds like another storyboard issue, the transition being the issue (if it works when it fades).

Could you file a bug report for this, please? :slight_smile: [import]uid: 52491 topic_id: 22712 reply_id: 90696[/import]