Pausing the World, or manually calling update/step...

I've been unable to figure out how to turn off the auto-update in the wck.World class. I really want to be able to pause and/or call the "step" or "update" function in wck.World myself, so i can control the playback of the simulation.

I looked at the source for wck.World, but 'step' expects an event, so it doesn't seem like something that should be called externally. Is there a simple switch to turn off the auto-step of the world, and then a simple method that i can call on my World instance?

Thanks,
jos

Code: Select all

myWorld.paused = true;

"step" is an event listener that is setup in the "create()" function via:

Code: Select all

listenWhileVisible(stage, Event.ENTER_FRAME, step);

Since the enter frame event instance isn't actually used, you can just call step manually via:

Code: Select all

myWorld.step(null);
That's excellent, thanks so much. I was obviously not thinking/looking at the source very clearly to have missed the 'pause' attribute.
Hyakugei wrote:I've been unable to figure out how to turn off the auto-update in the wck.World class. I really want to be able to pause and/or call the "step" or "update" function in wck.World myself, so i can control the playback of the simulation.

I looked at the source for wck.World, but 'step' expects an event, so it doesn't seem like something that should be called externally. Is there a simple switch to turn off the auto-step of the world, and then a simple method that i can call on my World instance?

Thanks,
jos



If I use myWorld.pause = false;

can I call a method that will change

myWorld.pause = true;

I tried this but its a no go. The world does not un pause.

Code: Select all

myWorld.paused = true;
//myWorld.debugDraw = true;
myWorld.gravityY = 18;

stage.addEventListener(MouseEvent.CLICK, testTrace);

function testTrace(e:MouseEvent):void
{
   myWorld.pause = true;
}
I tried this and that doesnt do the trick either.

Code: Select all

import com.greensock.*;
import flash.events.MouseEvent;

myWorld.debugDraw = true;
myWorld.gravityY = 18;
myWorld.paused = true;



stage.addEventListener(MouseEvent.CLICK, testTrace);

function testTrace(e:MouseEvent):void
{

   myWorld.step(null);
   TweenLite.to(myWorld.first, 1, {x:-115, y:118});
   TweenLite.to(myWorld.third, 1, {x:-115, y:118});

}
well just in case anyone cares or has the same problem.


Anyhow my problem is that I need to

myWorld.paused = true

and when I'm ready to start it again. I have to set that paused to false. Doh! Simple and can't beleive it didnt click for me. LOL!!!

myWorld.paused = false;
myWorld.step(null);

Anyhow, since than I been learning box2d flash and its helped me understand physics in general even more. I think I will still use wck for my project just because its fast to set up and I can focus on game dev more. Box2d set up is pretty intensive but the control is awesome. Anyhow still have more questions to answer to myself before I commit 100% to wck or box2dflash. Either way I guess im using box2d over fisix or APE.

Original thread: https://box2d.org/forum/viewtopic.php?t=6049