Jump to content

  • Log In with Google      Sign In   
  • Create Account


colorkey problems


Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.

  • You cannot reply to this topic
2 replies to this topic

#1 Djfix   Members   -  Reputation: 237

Like
0Likes
Like

Posted 24 August 2012 - 05:59 AM

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?

Sponsor:

#2 Servant of the Lord   Crossbones+   -  Reputation: 17052

Like
0Likes
Like

Posted 24 August 2012 - 08:06 PM

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()

It's perfectly fine to abbreviate my username to 'Servant' rather than copy+pasting it all the time.

[Fly with me on Twitter] [Google+] [My broken website]

All glory be to the Man at the right hand... On David's throne the King will reign, and the Government will rest upon His shoulders. All the earth will see the salvation of God.                                                                                                                                                       [Need free cloud storage? I personally like DropBox]

Of Stranger Flames - [indie turn-based rpg set in a para-historical French colony] | Indie RPG development journal


#3 Djfix   Members   -  Reputation: 237

Like
0Likes
Like

Posted 25 August 2012 - 09:29 AM

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.




Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.



PARTNERS