Vote count:
0
this is my first game and I'm not that experienced of a programmer but I've researched a lot and I've worked on this game every day for the last couple of weeks. I research different things on this website every day and I find your posts here tremendously helpful :)
I have a question regarding fixed timestep loops, can't wrap my head around why changing the time to wait between updates affects the speed of which my entire game moves. Maybe there's something I'm missing or something I don't understand yet
My loop looks like this:
private void gameLoop(){
final double updateWaitTime = 1000000000/50;
double nextUpdateTime = System.nanoTime();
while(running) {
double now = System.nanoTime();
while( now > nextUpdateTime) {
updateGame(now);
nextUpdateTime += updateWaitTime;
}
double interpolation = (now+updateWaitTime-nextUpdateTime)/updateWaitTime;
drawGame(interpolation);
}
}
If I decrease the value of updateWaitTime, my game moves much faster because it is getting updated so much more.
The methods that execute my movement looks like this, they both get the current time with getNanoSecond() which holds the same value that the gameLoop sets "now" as.
protected void travel(){
if(moveShotTime <= c.getNanoSecond()){
setX(getX()+dx);
setY(getY()+dy);
moveShotTime = c.getNanoSecond()+bulletMoveDelay;
}
}
//[0] = degree. [1] = distance. [2] = movementspeed
public void move(){
if(moves.isEmpty() == false){
ArrayList<double[]> movementDirection = moves.get(0);
if(movementDirection.isEmpty() == false){
double[] oneMove = movementDirection.get(0);
if(getNextMoveTime() <= c.getNanoSecond()){
else if(oneMove[1] > distanceMoved){
double radian = (oneMove[0]/360)*2*Math.PI;
double dx = round((Math.cos(radian)*oneMove[2]), 9);
double dy = round((Math.sin(radian)*oneMove[2]), 9);
double dz;
if(dx<0){
dz = round(dx/(Math.cos(radian)), 5);
}
else if(dx==0){
dz = dy;
}
else if(dy==0){
dz = dx;
}
else{
dz = round((dx/(Math.cos(radian))), 5);
}
setX(getX()+dx);
setY(getY()+dy);
if(dz<0){
distanceMoved = distanceMoved-dz;
}
else{
distanceMoved = distanceMoved+dz;
}
movedX = movedX + dx;
movedY = movedY + dy;
}
else{
movementDirection.remove(0);
distanceMoved = 0;
}
}
}
else{
setPreviousX(getX()-movedX);
setPreviousY(getY()-movedY);
moves.remove(0);
}
}
else{
}
}
So what I'm wondering is why changing the updateWaitTime affects the speed of everything. Since I'm using timestamps as a reference for when to execute the movement again, in my mind it shouldn't make a difference how often the game is updated as long as it's more often than the timesteps inside of the game. I'm new to this and I'm surely missing something here. I would also like to ask what a common update-time for games are on PC and android? If I can't figure this out I'm gonna have to set an update-time that I can't change to work with from here on (since i would have to adjust everything in the game).
Thanks in advance and thanks for all the great info on this website!! :)
Aucun commentaire:
Enregistrer un commentaire