Reputation: 43
I am trying to reduce the lag in my game as it is unbearable. I understand that when blitting large images I should expect some lag, but I don't see any ways to reduce it. I have the code here: https://gist.github.com/Mrmeguyme/ce1a844af21695d1b853ef88fe8de5aa
The background is 1280x720px, the ground is 1280x100px, and my character is 50x50px.
Upvotes: 2
Views: 2650
Reputation: 1321
See http://www.pygame.org/docs/ref/surface.html#pygame.Surface.convert_alpha
This is what I do for all my programs:
def loadify(img):
return pygame.image.load(img).convert_alpha()
I just replace pygame.image.load with loadify to save typing. This converts the image to the proper pixel format for faster and easier blitting.
Upvotes: 7
Reputation: 1880
Your images likely have per-pixel transparency. Convert them to opaque.
faster_surface = surface_loaded_directly_from_png.convert()
Of course this isn't applicable to the character, but for the background it will improve things a bit.
EDIT: I also notice you're not calling clock.tick() anywhere. That should smooth things out and removed perceived slowdowns that are actually just the CPU naturally speeding up and slowing down.
Upvotes: 2