"medic!": ragdoll progress

I'm having trouble with the ragdoll.  for one, I can't get the image to be transparent... that's a pygame thing. and the image flipping to follow direction of movement doesn't seem to work anymore... that's an error on my part in the player code, I think.  any advice is greatly appreciated if you happen to have the time.

(log in to comment)


You need either an image without an alpha channel, in which you call surface.set_colorkey([255,0,255]) on (the color being the color you want to make clear); or you need an image with an alpha channel, such as a .png, on which you call surface.convert_alpha(). If you are building your own surface, the first option is easiest, but you can also use pygame.Surface([w,h],pygame.SRCALPHA), which tells it to have a per-pixel alpha component in the surface.

I tend to prefer colorkeys unless you really need the per-pixel specification (alpha values in the image are not just 1 and 0).
thanks, that should help.  I'm using gimp to make my images, along with the pygame.draw functions, so I'd rather go with the per-pixel, since the rest of my images use them... If I get around to a redesign/cleanup, I'll consider adding colorkeys.  you too have earned a place on my special thanks.  (I'm doing this for a learning experience, so any help is valuable, not to mention that this is a solo project, the credits will be short no matter what)
Lol I'm just avoiding figuring out how to fix my game. The main problem with per pixel alphas is you can't do realtime fades of them easily. If you are creating surfaces in realtime it's also a bit simpler than remembering to do pygame.SRCALPHA - I almost always have to look that one up :)
yeah, I'm not doing either, but at the same time I'm trying to change a color to another, and it's being a pain... wait, I'll just make 4 images! doh! thanks! I come up with ideas as I explain my problems to others, another advantage of working on a team that I wish I had... oh well, next pyweek!
So PyGame really can't fade a sprite out? How do you live with that? Pyglet for life, bro!
i must be the only one in pyweek that doesn't like pyglet.
I've never tried it (pyglet or fading out a sprite), not to mention I saw a tutorial about how to fadeout a sprite by blitting it on a piece of background, then fading the whole thing, but I'm sticking with what I know for the time being, though messing with pyglet is on my todo list now
you can do transparent sprites in pygame, easy.  one note though, i i think i know where you are having you problems is that you cannot mix per-pixel alpha and sprite alpha.  for example, if you have a per-pixel surface from a convert_alpha(), then attempt to modify the alpha with set_alpha(), the surface will lose the per-pixel alpha. so annoying!  for pygame surfaces, it's one or the other.  i wrestled with this last pyweek on my game nein.  if you are really stuck on it, you can check out this mini-library:


there are a few alpha channel related functions that might just be what you are looking for.  specifically "adjust_alpha" and "darken_surf". they use numpy to modify the alpha channel of the image in place.  be sure to remove the cairo stuff from the file, because i don't think anybody really [directly] uses cairo for rendering and it would be a pain to get the libs going.

i have a trick for fading out surface.  make a surface that is the same size as the surface you want to fade out, then i fill it with black and set the alpha value to something low, like 10.  then, on each draw call, i blit the black surface over the original.  over time, the surface will slowly fade to black.
finally, if you are doing a rag doll and want smooth movement, you could consider using a vec2d object to manage the position of the object in your game, rather the a pygame rect.  a vec2d object will hold floating point numbers which will make fractional movement increments smoother and you can calculate the angle the sprite is facing by calling get_angle() on it.  Then take the angle and rotate using rotozoom.

Hope that helps!
I've gone through using vec2d and all that, I'm at the point where I'm making a series of points in .ini file format and drawing between them.  I don't have time since all day tomorrow will be taken up with content creation. so sorry, but I'm past the point where I would try a library.  Nice thing is, I have a bunch of half-started libraries, so I might make a ragdoll and level library after pyweek.  not to mention add on at some point.  of course that has to compete for my coding time for modding minecraft 1.8, now that it has official modding support, I'm very excited... wow, never had so many possible projects before... sweet!

I like more pyglet, but pygame can fade out a sprite. Obviously with performance penalties and the image loaded must be 32 bits with alpha channel.