-
import com.actionsnippet.qbox.*;
-
-
// change the frame rate and test...
-
stage.frameRate = 60;
-
-
[SWF(width = 800, height=600)]
-
-
var sim:QuickBox2D = new QuickBox2D(this);
-
-
-
var circle:Shape = Shape(addChild(new Shape()));
-
with(circle.graphics) beginFill(0), drawCircle(0,0,50);
-
circle.x = 100, circle.y = 100;
-
-
-
sim.start();
-
-
var startTime:Number;
-
// delay the start a bit
-
setTimeout(function():void {
-
startTime = getTimer();
-
sim.addEventListener(QuickBox2D.STEP, onTimeStep);
-
}, 500);
-
-
function onTimeStep(evt:Event):void{
-
-
circle.x += (600 - circle.x) / 12;
-
-
if ((600 - circle.x) <1.5){
-
trace("frameRate: ", stage.frameRate);
-
trace("totalTime: ", getTimer() - startTime +" ms");
-
trace("totalTimeSteps: ", sim.totalTimeSteps);
-
sim.removeEventListener(QuickBox2D.STEP, onTimeStep);
-
}
-
}
Note: This snippet requires QuickBox2D 1.0 or greater
Really not sure how I didn't think of doing this before last night... I realized that the simple FRIM code inside of QuickBox2D can be used to make any standard frame-based style ActionScript animation time-based. In this snippet I do a simple ease out one liner:
circle.x += (600 - circle.x) / 12;
Code like that on an enterFrame would run at different speeds depending on your framerate. However, if you run it on QuickBox2D's STEP event it runs independent of fram-erate. I'm obviously going to just wrap this up into it's own mini-library separate from QuickBox2D and do a more in depth post about it... but for now, this snippet just traces out the results. These are my results from my macbook pro dual 2.4 intel....
frameRate: 12
totalTime: 1165 ms
totalTimeSteps: 93
frameRate: 24
totalTime: 1162 ms
totalTimeSteps: 93
frameRate: 30
totalTime: 1166 ms
totalTimeSteps: 91
frameRate: 60
totalTime: 1167 ms
totalTimeSteps: 93
frameRate: 120
totalTime: 1168 ms
totalTimeSteps: 91
Anyway... will peel the FRIM code out of QuickBox2D and wrap it up in its own library sometime soon...