I've been working on a personal 2d HTML5 Canvas engine, and I am trying to implement Glenn Fiedlers fixed time step algorithm:
http://gafferongames.com/game-physics/fix-your-timestep/
I have read through these other examples of how Box2D did it:
http://www.unagames.com/blog/daniele/2010/06/fixed-time-step-implementation-box2d
http://blog.allanbishop.com/box-2d-2-1a-tutorial-part-10-fixed-time-step/
The problem I am having is that objects don't wrap around the edges of the screen properly.
For example, if I have a scrolling background, and the position gets to greater than 800, and I want to wrap it back around to 0, you can see it visually moving there, rather than instantly appearing.
I am thinking, perhaps i don't know the proper way to implement this awesome algorithm.
Here is a basic pseudo code of what I am doing...
function update(){
// code to determine time passed, etc
while (accumulated >= TIC) {
resetSmooth();
fixedUpdate( TIC );
accumulated -= TIC;
}
ticLeft = accumulated / TIC;
render(ticLeft)
}
function resetSmooth(){
renderPos = oldPos = currentPos;
}
function fixedUpdate( dt ){
oldPos = currentPos;
currentPos += velocity;
}
function render (ticLeft){
smooth = 1.0 - ticLeft;
renderPos = (currentPos * ticLeft) + (oldPos * smooth)
}
The smoothing is awesome, but it is just the wrap around warping that I need help figuring out. Also, in my collision detection and what not, do I use currentPos, oldPos, or renderPos ?
Thank you for any help, and here is a quick demo of what I am talking about:
It works in IE 10.0.4, Moz 20.0.1, and Chrome 26.0.1410.64 m