I am trying to figure out if there is a way to move a sprite smoothly on the screen at different speeds without stuttering, but keeping the effect that it's moving smoothly; especially at faster velocities.
Below is a basic version of what I have with all of the object specific logic stripped out for readability.
void MoveableGameObject::update(double time)
{
//maxVelocity is 10
currentVelocity = min<float>(currentVelocity + acceleration * time, maxVelocity);
location.x += currentVelocity;
}
void MoveableGameObject::draw()
{
sprite->draw(location.x, location.y)
}
The part that I do not like is that the next time the frame renders and max velocity has been achieved, the sprite jumps 10 pixels and looks stuttery. If I tone down the numbers then it is of course smoother, but also slower.
I need to find a way to still have the speed, but give a smooth transition somehow. I am having a hard time wrapping my head around trying to implement movement speeds. Am I just using the wrong scale in terms of velocity to pixels?
My brain hurts, but I am still having a blast tinkering around with this and is a nice change of pace from doing nothing but business applications for the past 7 years.
I do have the ability to say run the game logic 20 times a second while rendering at 60 frames a second. Figured I would mention that in case that helps with an answer. Currently they are both just set to 60 since I am only running a single sprite and wanted to test the movement and check the sprite location on update()
vs. draw()
.
Thanks in advance for any help.
EDIT: I forgot to mention and not sure if it matters or not, but I am currently using SDL to render.