Fading Intro

BlitzMax Forums/BlitzMax Programming/Fading Intro

gellyware(Posted 2006) [#1]
Does anyone have any examples of how to fade an intro screen (displaying a white background with logo) into either a game screen or black?


degac(Posted 2006) [#2]
uhh...I'm writing something for my incoming game...
try this one


and this one is the main prog


of course you can change it if you want - and some things are not needed...you can just use the basic Bmax commands (see the type function Update/Draw)
Hope this helps
byez


ImaginaryHuman(Posted 2006) [#3]
Draw your game screen. Then draw the title screen over the top of it, with a variable level of alpha blending in SetBlend AlphaBlend. Start with a solid title screen image and then vary the alpha to fade it out.


FlameDuck(Posted 2006) [#4]
What AngelDaniel said.


gellyware(Posted 2006) [#5]
Thanks for the input, degac your code got me thinking about some different things and here is the splash screen I came up with if anyone is interested.



Type TSplash
	Global list:TList= CreateList()
	
	Const alphaMax# = 1
	Const alphaMin# = 0
	Const fOUT = 0
	Const fIN = 1

	
	Field image:TImage 
	Field alpha#
	Field fade_duration
	Field hold_duration 
	
	Field milli
	Field mode    
	
	Function Create:TSplash(img:Object, width=800, Height=600)  
	
		'
		' CODE BELOW CREATES THE IMAGE THAT WILL BE FADED
		' CHANGE TO SUIT YOUR NEEDS 
		'                                                  
		
		Local image0:TImage = LoadImage(img)
		If not image0 Then RuntimeError("Unable to load splash logo!")   
		Local image1:TImage = CreateImage(width,Height,1,DYNAMICIMAGE|MASKEDIMAGE)
		                                       
		                                   
		MidHandleImage image0
		
		SetClsColor (255 , 255 , 255)
		Cls 
				
		DrawImage image0, width/2, Height/2
		GrabImage image1, 0, 0

		SetClsColor(0,0,0)
				
		Local splash:TSplash=New TSplash
			splash.image = image1
			splash.alpha = 1
			splash.fade_duration = 2000
			splash.hold_duration = 3000
			splash.milli = MilliSecs()
			splash.mode = splash.fOUT 
		ListAddLast list,splash
		
		Return splash
	End Function
	

	
	Method SetFadeIn(hd=2000, fd=2000)
		alpha = 0
		milli = MilliSecs()
		hold_duration = hd 
		fade_duration = fd 		
		mode = fIN	
	End Method
	
	Method SetFadeOut(hd=2000, fd=2000)
		alpha = 1
		milli = MilliSecs()
		hold_duration = hd 
		fade_duration = fd 	
		mode  = fOUT 
	End Method


	Function Update()
		Local stillGoing = False
		Local r
		
		For Local s:TSplash=EachIn list
			r = s.Draw()
			If not r Then stillGoing=True  
		Next  
		If not stillGoing       
			For Local s:TSplash=EachIn list
				s.image = Null 
				s.list.Remove s
			Next
		EndIf 
		
		Return stillGoing		
	End Function
	
	Method Draw()
		Local tt# , tl# 'total time, time left
		Local r# 		'result 
		  
		If mode = fOUT  
			If MilliSecs() > hold_duration + milli
				If MilliSecs() > fade_duration + hold_duration + milli Return 1 
				tt# = fade_duration + hold_duration + milli
				tl# = tt - MilliSecs()
				r# = Abs((tl / fade_duration) )		
				If r <= 0 Return 1             
				
				alpha = r			 	    
			EndIf
		EndIf 			
					
		If mode = fIN
				If MilliSecs() > fade_duration + hold_duration + milli Return 1 
				tt# = fade_duration + hold_duration + milli
				tl# = tt - MilliSecs()
				r# = Abs((tl / fade_duration) )   
				Print r
				If r <= 0 Return 1
				alpha = r				
		EndIf   
		
		Local prevBlend = GetBlend()
		
		SetAlpha(alpha)
		SetBlend(ALPHABLEND) 
		DrawImage image , 0 , 0 	
		SetBlend(prevBlend)	
		SetAlpha(1)
	EndMethod 
	
End Type


'
'test
'


Graphics 800,600
'fade out demo
'SetFadeOut(hold_duration, fade_duration)
'hold duration = length to hold graphic before fading OUT (in millisecs)
'fade duration = how long should the fade take to fade out (in millisecs)
Local splash:TSplash=TSplash.Create("image.png")
splash.SetFadeOut(2000 , 1000)

Local done = False 
While not done
	Cls
	If not TSplash.Update() done = True
	Flip 
Wend 

 
'fade in demo
'SetFadeIn(hold_duration, fade_duration)
'hold duration = length to hold graphic AFTER fading in (in millisecs)
'fade duration = how long should the fade take to fade in(in millisecs)
	                                                                     
	
splash:TSplash=TSplash.Create("image.png")
splash.SetFadeIn(2000 , 1000)

done = False 
While not done
	Cls
	If not TSplash.Update() done = True
	Flip 
Wend 

End



xlsior(Posted 2006) [#6]
My old fade-to-black routine from the Code Archives:

http://www.blitzbasic.com/codearcs/codearcs.php?code=1281

(Also does a fade-to-white, and a smooth cross-fade from one image into another)


gellyware(Posted 2006) [#7]
If I had only seen that yesterday... I'd be a couple hours richer!!!


:)