"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)
Comments
nein. if you are really stuck on it, you can check out this mini-library:
http://fallenspire.googlecode.com/svn-history/r35/trunk/game/utils.py
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!
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 http://fallenspire.googlecode.com/svn-history/r35/trunk/game/utils.py
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 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.
saluk on 2011/09/15 18:31:
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).