The executable jar is here http://www.angelfire.com/clone/wolfbane/test.jar Does anyone wish to help me figure out why this stutters. I used the discete timming step loop as described by Markus Persson, and the GAGE timer. Here is the code for the loop:
public void go()
{
float interpolation;
long time;
previousTime = timer.getClockTicks();
passedTime = 0;
while (true) //run until quit app
{
interpolation = passedTime/(float)milliseconds_per_gametick;
frametime = timer.getClockTicks();
clientTick(interpolation);
fps = timer.getTicksPerSecond() / (timer.getClockTicks()-frametime);
time = timer.getClockTicks();
passedTime += (time-previousTime);
previousTime = time;
while (passedTime>milliseconds_per_gametick)
{
gameTick();
passedTime-=milliseconds_per_gametick;
}
////////////////////////////////////////////
//check exit condition
if (exit == 1)
{
gd.setFullScreenWindow(null);
System.exit(0);
}
////////////////////////////////////////////
}//close while animation loop
} //closes the go method
/////////CLIENTTICK///////////////////////////
private void clientTick(float interpolation)
{
Xposition(xPlayerPos.getValue(interpolation));
render(); //draws everything to the backbuffer
bs.show(); //page flip backbuffer
}
/////////GAMETICK///////////////////////////
private void gameTick()
{
float xPos = xPlayerPos.getValue(1);
if (xPos >= 800 || xPos < 0)
vx = -vx;
xPos += vx;
xPlayerPos.setValue(xPos);
}
private void Xposition(float xpos)
{
xP =(int) xpos;
//System.out.print(" " + xP);
}
At first I thought that it was the interpolation, but I looked at the x positions and they never skip back and forth. The x is always in increments of 2 or 3 pix so that is not the cause. The value on the right is the frame rate and that does skip around and sometimes beyond the refresh rate so I think that has something to do with the stutter.