- 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!
6 replies to this topic
#1 Members - Reputation: 119
Posted 24 September 2012 - 11:45 AM
Hello Everyone,
Ad:
#2 Moderator* - Reputation: 5335
Posted 24 September 2012 - 11:50 AM
Use floating point data types instead of integers?
[ I was ninja'd 71 times before I stopped counting a long time ago ] [ f.k.a. MikeTacular ] [ My Blog ] [ SWFer: Gaplessly looped MP3s in your Flash games ]
#4 Crossbones+ - Reputation: 1328
Posted 24 September 2012 - 12:02 PM
First of all, I assume we are talking about a 2D game in which your objects are sprites, right? -- (because otherwise you wouldn't be talking about pixels).
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.
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.
#6 Crossbones+ - Reputation: 1373
Posted 28 September 2012 - 08:41 PM
Move it using the frame time of your function.
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.
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 photo editor.
Here's Breakout:
Breakout!
If you need some photo editing done, contact me:
superman3275@gmail.com
if you want some programming help, or are recruiting for a game development team, either PM me on here or email me up there
!
Here's Breakout:
Breakout!
If you need some photo editing done, contact me:
superman3275@gmail.com
if you want some programming help, or are recruiting for a game development team, either PM me on here or email me up there
#7 Members - Reputation: 751
Posted 28 September 2012 - 09:41 PM
When you place your object just cast the float to an int. When you cast it the decimal part will be ignored. So you can round it first if you wish, then anything over .5 should be +1.
Edited by EddieV223, 28 September 2012 - 09:50 PM.
If this post was helpful and/or constructive please give rep.
SFML2.0 Nightly Download Link http://en.sfml-dev.org/forums/index.php?topic=9513.0
SFML2.0 Tutorials http://www.sfml-dev.org/tutorials/2.0/






