Jump to content
  • Advertisement
Sign in to follow this  
Gabriel Marincu

colorkey problems

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

If you intended to correct an error in the post then please contact us.

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 this post


Link to post
Share on other sites
Advertisement
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 this post


Link to post
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.

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

Participate in the game development conversation and more when you create an account on GameDev.net!

Sign me up!