# colorkey problems

This topic is 2300 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

## Recommended Posts

Hello everyone...I've recently managed to put up some code for a tile based game and it's working well but i've encountered a problem.
I want to use non-colorkeyed images as base tiles(grass,dirt,rock,road), but if i draw a higher resolution image and load it with Pygame's basic image loading function (pygame.image.load) it lags a lot, but if i make the (0,0) pixel white and colorkey that, it works with no lag but it wrecks my tile grid's appearence.

Any ideas why that might happen?

##### Share on other sites
I don't use Python or PyGame, but I know PyGame is based on SDL (a C-language library) which I am familiar with. SDL images are sometimes loaded in formats that aren't the same format as the one being drawn to, causing slowdowns as each draw has to perform some conversions. Typically the solution is to convert the images once, after you load them, instead of costly converting them every draw. I'm guessing this same problem is what is occurring in your PyGame program, and your color-keying probably is converting the images for you without you realizing it.

A few google searches shows that this is likely your problem. See here.
Try calling this code after you load the image but before you start using it for drawing:
myImage = myImage.convert()
It should convert your image to the same image format as the screen (so no conversions are needed when rendering to the screen).
Note: You can't just call:
myImage.convert()
...because convert() returns a new copy without altering the old, so you have to make sure to catch the return value.
It must be:
myImage = myImage.convert()

##### Share on other sites
Thanks! I've applied this function to my images and it has reduced the lag but I found out that most part of the lag was because i was calling the map loading function each time the game loop iterated.I fixed both of those problems and now it works like a charm.

1. 1
2. 2
3. 3
Rutin
15
4. 4
5. 5

• 9
• 9
• 11
• 11
• 23
• ### Forum Statistics

• Total Topics
633678
• Total Posts
3013292
×