Yes, I know that there are similar questions out there, and I have read through them, but they do not help me (or most likely I just don't understand them enough to use them).
FYI: I do not use classes, or anything like that.
The Problem
So what I am trying to do is make security cameras in my game. It moves/pans the image left until the image reaches the edge, waits like 1 second or something, then it moves/pans the image right until the image reaches the edge, wait 1 second or something, repeats. I have accomplished that, but the resulting animation looks jerky/laggy. I wish to make the animation smoother and less jerky/laggy.
EDIT: I also want to keep the same speed of the animation if possible
Here is my code;
if var_bounce == 0:
if var_x <= -207:
if var_x_timer == 10:
var_x = var_x + 10
var_bounce = 1
var_x_timer = 0
else:
var_x_timer = var_x_timer + 1
else:
var_x = var_x - 10
if var_bounce == 1:
if var_x >= 0:
if var_x_timer == 10:
var_x = var_x - 10
var_bounce = 0
var_x_timer = 0
else:
var_x_timer = var_x_timer + 1
else:
var_x = var_x + 10
Some Variables and Values Explained
The
var_x
is the x value which I just place in the x value spot when I use theblit
function.E.g.
screen.blit(image, (var_x, 0))
The
var_x_timer
is the timer for when it needs to wait for the 1 second or something.The reason why I am using the framerate of my program rather than use a timer function because 1) I did not want to sleep/delay/stop the program just for this, and 2) I don't need it to be precise when waiting.
The
var_bounce
is just a way for the program to know that it has reached the edge and needs to go in the opposite direction.The minimum and maximum x values are
0
and-207
respectively and this is so that the image still covers the entire screen. I got these values through trial and error, so no need to change those.
Other/Additional Information
The size of my images for the security cameras is
1600 x 718
The screen size is
1366 x 718
My Code in Action
(Ignore the other stuff)
(Looped)