8
« on: November 13, 2011, 05:22:47 pm »
I have a player that is moved when the left or right arrows is pressed, and on my computer making him move by 0.5 (pixels?) every update looks OK. But on other, faster computers there will be faster updates so the player will move faster, and slower on slower computers. I've tried using a clock and moving the player using this alogarithm:
sprite.Move(speed / (1 / clock.GetElapsedTime()));
The clock will measure it in how many seconds it takes for an update to come (let's call it SPF for seconds per frame) so I've converted it to FPS (frames per second) by dividing 1 by it. I've used this number to divide the speed by so the speed should, by my calculations, be how many pixels it moves every second. But even having the speed at a high number like 200, the player moves very slowly. I'm not sure I'm managing the fps very well. Does anyone know how to make sure the sprite is moving the same speed on all computers?[/code]