Hi All,
I'm developing a physics-based game to be able to target different platforms using OpenFL (the successor of NME) and the Box2D port I use is in Haxe: https://github.com/jgranick/box2d,
however I the issue I have is probably generic enough to be recognized by users of other ports.
I'm trying to implement the fixed-timestep loop decoupled from rendering as outlined here http://gafferongames.com/game-physics/fix-your-timestep/ and even though I seem to be doing everything by the book the render still produces a noticeable stutter.
Attached is an SWF that should illustrate it: http://www.openfl.org/download_file/747/14508/
The main part looks like this:
And this is where I update graphics, interpolating position (some less relevant code related to my implementation removed) :
If anyone's interested to see the full source code, here's a buildable (requires Haxe, OpenFL with Box2D and Spritesheet haxelibs) test project which I tried to make as simple as possible to get my point across:
https://github.com/olegr1/openfl-box2d-tilesheet-test
Thanks for looking into it!
I'm developing a physics-based game to be able to target different platforms using OpenFL (the successor of NME) and the Box2D port I use is in Haxe: https://github.com/jgranick/box2d,
however I the issue I have is probably generic enough to be recognized by users of other ports.
I'm trying to implement the fixed-timestep loop decoupled from rendering as outlined here http://gafferongames.com/game-physics/fix-your-timestep/ and even though I seem to be doing everything by the book the render still produces a noticeable stutter.
Attached is an SWF that should illustrate it: http://www.openfl.org/download_file/747/14508/
The main part looks like this:
Code: Select all
function enterFrameHandler(ev:Event):Void {
var timeStep:Float = 1/60;
var currentTime:Int = Lib.getTimer();
var frameTime:Float = (currentTime - prevTime) / 1000;
if ( frameTime > 0.25 )
frameTime = 0.25;
prevTime = currentTime;
timeAccumulator += frameTime;
while(timeAccumulator >= timeStep)
{
updatePhysics(timeStep);
timeAccumulator -= timeStep;
}
var alpha:Float = timeAccumulator / timeStep;
updateGraphics(alpha);
}
And this is where I update graphics, interpolating position (some less relevant code related to my implementation removed) :
Code: Select all
function updateGraphics(alpha:Float):Void
{
for (b in gameBodies)
{
var posX:Float = b.getPosition().x * PHYSICS_SCALE;
var posY:Float = b.getPosition().y * PHYSICS_SCALE;
var posXIntp:Float = userData.prevPosX * (1 - alpha) + posX * alpha;
var posYIntp:Float = userData.prevPosY * (1 - alpha) + posY * alpha;
//More code here...
If anyone's interested to see the full source code, here's a buildable (requires Haxe, OpenFL with Box2D and Spritesheet haxelibs) test project which I tried to make as simple as possible to get my point across:
https://github.com/olegr1/openfl-box2d-tilesheet-test
Thanks for looking into it!