The game I am creating is tile-based. Movement is per-tile, as one would expect a tile-based game to be. This means that the player presses to go left once, the character automatically moves to the left the space of a single tile.
I decided that it jumping from tile to tile just didn’t look professional enough(http://glasszee.tumblr.com/post/24288781615/camera-movement-is-still-choppy-moving-one-tile), so I added a certain thing that moved the camera to the left bit by bit. Say the distance between a tile was 32 pixels. What it does in the video is go straight from 0 to -32. But I changed it so that you press left, and the x coordinate will go 0, -1, -2, -3, -4, -5, -6, all the way to -32. I printed the x coordinate out, and it’s apparently working. The problem is that it’s moving so fast that you can’t even comprehend that it’s moving. Which isn’t surprising-- at 200 frames per second, the difference between 2 frames and 32 frames won’t seem like that much.
How do I slow down the time between the 0, -1, -2, -3, etc? Maybe OpenGL has a way for it to wait a certain amount of time before going to the next frame, while not stopping other areas of the code?
EDIT: Here is some relevant code that you may want to see.
if(isMoving){
while(x == 0){
switch(direction){
case 0: desiredY=yAdd+(scale*s);//scale*s is the length of a tile
break;
case 1: desiredX=xAdd+(scale*s);
break;
case 2: desiredY=yAdd-(scale*s);
break;
case 3: desiredX=xAdd-(scale*s);
break;
}
x = 1;/*this wonky thing is to have this happen once every 'isMoving' occasion,
or else the desiredX or Y will always be (scale*s) more extreme than xAdd and it'll go on forever.*/
}
}
if(xAdd<desiredX){ /*the reason it's not a 'while' is because, to my understanding, it only renders when it reaches
Display.update(). A 'while' would have it move to -32 before updating even once.*/
xAdd+=1;
} else if(xAdd>desiredX){
xAdd-=1;
} else if(yAdd<desiredY){
yAdd+=1;
} else if(yAdd>desiredY){
yAdd-=1;
} else {
isMoving=false;
x = 0; //now it's not moving anymore, so everything resets.
//glBindTexture, glBegin, etc.
}