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?
Fading Intro
BlitzMax Forums/BlitzMax Programming/Fading Intro 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
try this one
'fx_image Global list_imageFX:tlist=New tlist Type timagefx Global event_raise:Int=0 Field image Field v_alpha:Float,i_alpha#=-.01 Field l_alpha:Float=1 Field fademode=1 Field x#,y# Field dx#,dy# Field rot#=0,i_rot#=0 Field scale_x#=1 Field scale_y#=1 Field scale_dx#=0 Field scale_dy#=0 Field status=0 Field action=0 Field strip_number=10 Field color[3] Field blendMode=ALPHABLEND Field checked:Int=0 Field duration:Int ' ' control the audio (optional) Field channel:TChannel Field volume:Float Field volume_delta:Float Function Add:timageFx(_image:timage,action=0) Local t_imagefx:timagefx=New timageFX t_imageFX.image=_image t_imageFX.color[0]=255 t_imageFX.color[1]=255 t_imageFX.color[2]=255 t_imageFX.v_alpha=1.0 t_imageFX.l_alpha=0 t_imageFX.action=action ListAddLast list_imageFX,t_imageFX Return t_imageFX End Function Method Strip(n=10) action=action|1 strip_number=n End Method Method Alpha(_alp#,i_alp#=0.1) v_alpha=_alp i_alpha=i_alp End Method Method SetFadeIn(timer=2000) v_alpha=0 i_alpha=Float(100)/timer l_alpha=1 fademode=0 duration=timer 'Print "Fade IN "+v_alpha+" INC: ("+i_alpha+")" End Method Method SetFadeOut(timer=2000) v_alpha=1 i_alpha=-Float(100)/timer l_alpha=0 fademode=1 duration=timer 'Print "Fade OUT "+v_alpha+" INC: ("+i_alpha+")" End Method ' End Rem Method AudioFade(chan:TChannel,vol_s:Float) If duration=0 Return channel=chan volume=vol_s volume_delta=Float(100)/duration End Method Method SetColor(r,g,b) color[0]=r color[1]=g color[2]=b End Method Function ClearAll() For Local t:timageFX=EachIn list_imageFX ListRemove list_imageFX,t t.image=Null t=Null Next End Function Function Update() For Local t:timageFX=EachIn list_imageFX rit:Int=t.draw() Next Return rit End Function Method Draw() Select action Case 0' fade in & out If fademode=0 v_alpha=v_alpha+i_alpha volume=volume+volume_delta If v_alpha>l_alpha status=1;Return 1 Else v_alpha=v_alpha+i_alpha volume=volume-volume_delta If v_alpha<l_alpha status=1;Return 1 End If Case 1 If checked=0 loop_s=0 loop_f=GraphicsHeight()/strip_number LOOP_2=0 loop_stp=loop_f checked=1 End If End Select If volume<0 volume=0 If volume>1 volume=1 If channel<>Null SetChannelVolume channel,volume ' vol:-delta_vol ResumeChannel channel End If 'draw image... o_blend=GetBlend() o_alpha#=GetAlpha() GetColor(O_r,O_g,O_b) GetScale(o_x#,o_y#) SetBlend BLENDmode SetScale 1,1 SetAlpha v_alpha SetColor color[0],color[1],color[2] DrawImage image,x,y Select action Case 1 SetColor 0,0,0 Repeat DrawRect 0,loop_s,GraphicsWidth(),loop_2 loop_S:+loop_stp loop_2:+1 Until loop_s>=loop_f End Select SetBlend o_blend SetScale o_X,o_Y SetAlpha o_alpha SetColor o_r,o_g,O_b End Method End Type
and this one is the main prog
'test Graphics 640,480 Include "fx_image.bmx" Global image=LoadImage("gfx/bkg_04.png") myfx:timagefx=timagefx.add(image) myfx.SetFadeOut(10000) Repeat Cls ris=timagefx.update() Flip Until MouseHit(1) Or ris=1 myfx.SetFadeIn(10000) Repeat Cls ris=timagefx.update() Flip Until MouseHit(1) Or ris=1 End
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
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.
What AngelDaniel said.
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
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)
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)
If I had only seen that yesterday... I'd be a couple hours richer!!!
:)
:)