- I update the position of my objects every time I go through my game loop
- I have a function that calculates the number of loops per second, lets say there are 100
- I want to move my object at a constant rate of 30 pixels per second (which is already quite fast)
- This means that I should move my object 0.3 pixels per loop
- This is a problem!
Moving a constant number of pixels per second
Members - Reputation: 119
Posted 24 September 2012 - 11:45 AM
Crossbones+ - Reputation: 2423
Posted 24 September 2012 - 12:02 PM
So, yeah, use floats for position values like Cornstalks says above.
But what game framework or library are you using? Does it support drawing with subpixel accuracy? If not you have to round to the nearest pixel ... this tends to look jerky imho though. Basically do all your logic/updates in terms of floating point values and convert to the nearest pixel just before blitting. Or switch to a 2D framework that lets you draw to float locations.
Edited by jwezorek, 24 September 2012 - 12:04 PM.
Crossbones+ - Reputation: 2061
Posted 28 September 2012 - 08:41 PM
That means that you multiply your speed variables by the frame time of your window. Since time is constant, it will move at the same speed on everyones screen.
I'm a game programmer and computer science ninja !
Here's my 2D RPG-Ish Platformer Programmed in Python + Pygame, with a Custom Level Editor and Rendering System!
Here's my Custom IDE / Debugger Programmed in Pure Python and Designed from the Ground Up for Programming Education!
or Personal-Message me on here !
Members - Reputation: 1823
Posted 28 September 2012 - 09:41 PM
Edited by EddieV223, 28 September 2012 - 09:50 PM.
If this post or signature was helpful and/or constructive please give rep.
// C++ Video tutorials
// Easy to learn 2D Game Library c++
SFML2.2 Download http://www.sfml-dev.org/download.php
SFML2.2 Tutorials http://www.sfml-dev.org/tutorials/2.2/
// Excellent 2d physics library Box2D
// SFML 2 book