Trouble with fades...

BlitzMax Forums/BlitzMax Programming/Trouble with fades...

Bukky(Posted 2006) [#1]
Hey guys,

I'm having a bit of trouble implementing a fade between level transitions.

Here is the pseudocode for half of the transition:


Function fadeTransition()
	SetBlend alphablend 
	Local SplashCounter = 0 
	
	Local alphaValue:Float = 0.0 
	
	While SplashCounter < 50 
		


		DrawLevel()
		DrawChars()
	
		SetAlpha alphaValue 
		
		TileImage white_fade
		
		SetAlpha 1.0		
		
		
		alphaValue = alphaValue + 0.02

		SplashCounter = SplashCounter + 1
		
		
		Flip 
		Cls 
		
	Wend 
End function 




All I get is a white screen. When I remove the line that says "SetAlpha 1.0", I get a weird washout effect. I've had fades working before, as I've used a similar method in my previous game for a splashscreen. Anyone have any ideas as to why it is not working now?


xlsior(Posted 2006) [#2]
What kind of effect are you trying to accomplish? Without knowing that, it's hard to give specific pointers.

You may find the following of use, something I put in the code archives last year: http://blitzbasic.com/codearcs/codearcs.php?code=1281
Fade to black, fade to white, and a crossfade between two images.

And another one I did, that's somewhat related: http://blitzbasic.com/codearcs/codearcs.php?code=1282
Fade an image from color to black-and-white, and back again.

(Note: these were written quite a while ago. You'll need to remove the 'flushmem' command from the linked sources, it is no longer necessary/supported.)


Bukky(Posted 2006) [#3]
Hey,

Sorry, I should have been more specific. I am trying to fade to white when a level is finished, load the new level, and then fade from white to the newly loaded level. That's what happens when I code and try to make coherent posts at 1 AM, haha. ;)


Bukky(Posted 2006) [#4]
Ok, I've revised and commented my code in order to make it a little easier to read:


Function fadeTransition()
	SetBlend alphablend 
	Local SplashCounter = 0  'value which is iterated in order to keep track of the loop 
	Local alphaValue:Float = 0.0 'value which sets the opacity value for the white tiles in the loop
	
	
	
	While SplashCounter < 50 
		
		If KeyHit(KEY_Enter) Or KeyHit(KEY_Space) Then 
		
		End If 
		
		If MouseHit(1) Then 
		
		End If 

		SetAlpha 1.0 'sets the opacity to 100% so that the stage can be drawn

		DrawLevel() 'routines for drawing the current stage
		DrawChars() 'routines for drawing the characters
	
		SetAlpha alphaValue 'the opacity is set to a variable so that the white tiles may be drawn
		
		TileImage white_fade 'white tiles are drawn across the screen
			
		alphaValue = alphaValue + 0.02 'the opacity value is incremented for the next trip through the loop

		SplashCounter = SplashCounter + 1 'the loop counter is iterated
		
		
		Flip
		Cls
		

	Wend 
        
       'Code for unloading old level and loading a new one goes here

     'level fades back in here

End Function 



What I dont understand is why I just get a white screen when I include the "SetAlpha 1.0" line. Does anyone have any ideas?


Grey Alien(Posted 2006) [#5]
I'd guess that that maybe you are resetting the blend to SolidBlend by accident somewhere in your DrawLevels or DrawChars functions. Then the white tiles are draw solid.


Bukky(Posted 2006) [#6]
Hey Grey Alien,

Good call! That fixed it :) Thanks.


Grey Alien(Posted 2006) [#7]
YES! nice one. I feel I've atoned for trying to sell someone my framework earlier who was asking about hiding the mouse cursor ;-)