While finishing up game loop and rendering integration, i made some blocks move back and forth in the x axis to test things out. Their initial positions are as follows:
The first block starts at 0,0(Top-left) and subsequent ones add 40 to both x and y.
Move code
s16 speed = 10;
if(block->sprite->position.x >= viewportWidth - block->sprite->width)
{
block->sprite->position.x = viewportWidth - block->sprite->width;
block->dir = -1;
}
else if(block->sprite->position.x <= 0)
{
block->sprite->position.x = 0;
block->dir = 1;
}
block->sprite->position.x += speed * block->dir;
However, if i change the speed to a number not multiple of 10(or using deltaTime to influence the speed), the blocks will de-sync when changin directions, as shown bellow:
Result of using roundf(1000 * deltaTime) as speed
Result of using 13 speed and removing the clamping of position
I thought it was related to me using ints instead of floats for positions, tried to change but no luck. Looking at the game loop update, no block is being left out of any update phase either.
What bit of math an i missing? What causes this?
Thanks.