[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[pygame] alpha (fading) with surfarray



Hi!

I have some "strange" problems when trying to do per-pixel alpha blending in 
combination with numeric... Hope anybody of you could give me a hint... ;)


I use fixed point arithmetic (for 2 reasons: 1. faster and 2. I could not 
make Numeric.multiply(...) to take floats so the only thing I could do is 
divide alpha by 2 but that step was too big)
Here is the code I currently use to fade out a surface:

def doFadeOut(thisSprite, bgImage):
	global __mainScreen

	newSurface = thisSprite.image.convert_alpha()
	thisSprite.image = newSurface


	alpha =	pygame.surfarray.pixels_alpha(thisSprite.image)
	origAlpha = alpha.astype('s')

	for i in range(9,1,-1):

		factor = 0.1 * i

		alpha2 = origAlpha

		#compute multiplicator
		multiplicator = array(factor * 256).astype('b')
		multiply(alpha2, multiplicator, alpha2)

		#shift 8 bits to the right
		right_shift(alpha2, array(8).astype('b'), alpha2)

                #convert
		alpha2 = alpha2.astype('b')

		#copy from alpha2 to original sprite surface's alpha
		alpha[:,:] = alpha2[:,:]



		´#and update
		objects.info.clear(__mainScreen, bgImage)
		__mainScreen.blit(bgImage, (0,0))
		objects.info.update()
		dirtyRects = objects.info.draw(__mainScreen)
		pygame.display.flip()

                #wait for some time (usually should not hardcode this)		     
    pygame.time.wait(40)



one problem is that as soon as my "fade-factor" is bigger than 0.5 I get an 
integer-overflow???


THANKS in advance for your help!





_________________________________________________________________
MSN Photos is the easiest way to share and print your photos: 
http://photos.msn.com/support/worldwide.aspx

____________________________________
pygame mailing list
pygame-users@seul.org
http://pygame.seul.org