I'm creating a flappy bird clone in pygame, and I'm having some weird graphical bugs that I have no idea how to solve.
In order to keep track of the pipes in the game, I have a list called pipes
. This list starts out empty when the game starts, and lists containing x and y coordinates are added as the current pipes move to the left of the screen:
def create_new_pipe(): # A function that adds a new pipe to the pipe list when called
bottom_pipe_position = random.randrange(24+pipe_vertical_spacing, screenh-168)
pipes.extend([
[screenw+pipe_horizontal_spacing, bottom_pipe_position],
[screenw+pipe_horizontal_spacing, bottom_pipe_position-320-pipe_vertical_spacing]])
Every frame the game checks to see if the list is empty (aka there aren't any pipes) or none of the pipes are off the right side of the screen, and if either conditions are met, it generates a new set of randomly positioned pipes:
if not pipes or max([pipe[0] for pipe in pipes]) < screenw-52:
# Creating a new pipe if no pipes are present or none of the pipes are off the right side of the screen
create_new_pipe()
Then, every frame every pipe is looped through and rendered accordingly, and moved to the left to progress the game. If any of the pipes are completely off the left side of the screen, they are removed from the list and are not rendered:
for pipe in pipes:
if pipe[0] < -52: # Removes any pipes that are completely off the left side of the screen
pipes.remove(pipe)
else:
pipe[0] -= 2 # Moving the pipes 2 pixels every frame
if pipes.index(pipe) % 2: # Rendering every odd pipe normally, and every even pipe flipped
screen.blit(pipe_image_flipped, pipe)
else:
screen.blit(pipe_image, pipe)
While this technically works, whenever I run the game some weird graphical glitches occur. Every time a new set of pipes is added, all the pipes flicker and the bottom pipes shift slightly to the left:
Is this a mistake done on my part or is it a limitation with the engine itself?