December 04, 2020, 10:28:59 AM

Author Topic: [bb] fast fading of 2d or 3d screen by Tracer [ 1+ years ago ]  (Read 473 times)

Offline BlitzBot

  • Jr. Member
  • **
  • Posts: 1
Title : fast fading of 2d or 3d screen
Author : Tracer
Posted : 1+ years ago

Description : What this does is stick a black (or other color) sprite just in front of the camera and alpha fades this in or out to "imitate" a screen fade. Uses a 3D on top of 2D technique but can obviously be adapted to work with 3D as well.

Code :
Code: BlitzBasic
  1. ; ########################################
  2. ; # CHEATED FADING USING 3D ON TOP OF 2D #
  3. ; ########################################
  4. ; #   BY TRACER (tracer@darkeffect.com)  #
  5. ; ########################################
  6.  
  7. Graphics3D 640,480,0,2                          ; 3D mode
  8.  
  9. ; create something to fade to and from
  10. Global logo = CreateImage(640,480)
  11. SetBuffer ImageBuffer(logo)
  12. For t = 1 To 10000
  13.         Color Rnd(100,255),Rnd(100,255),Rnd(100,255)
  14.         Rect Rnd(0,639),Rnd(0,479),Rnd(10,50),Rnd(10,50)
  15. Next
  16. SetBuffer BackBuffer()
  17.  
  18. camera = CreateCamera()
  19. CameraClsMode camera,0,1 ; NEEDED! for 3d on top of 2D
  20.  
  21. Global fade_sprite = CreateSprite() ; create sprite
  22.  
  23. ; color of sprite, this determines the color to fade from and to
  24. EntityColor fade_sprite,0,0,0
  25.  
  26. MoveEntity fade_sprite,0,0,1 ; move to just before camera
  27. EntityOrder fade_sprite,-100 ; make sure it gets drawn last
  28.  
  29. Delay 1000
  30.  
  31. intro()
  32.  
  33. Function intro()
  34.         Local fade_in = False
  35.         Local fade_out = False
  36.         Local done = False
  37.         Local fade_level# = 1
  38.         Local timer = 0
  39.        
  40.         While done = False
  41.                 timer = timer + 1
  42.                
  43.                 If timer = 100
  44.                         fade_in = True
  45.                 EndIf
  46.                
  47.                 Cls
  48.                 ; background 2d (included in fade)
  49.  
  50.                 DrawImage logo,0,0
  51.                        
  52.                 ; 3D (used for 3d sprite that does fade)
  53.        
  54.                 If fade_in = True
  55.                         EntityAlpha fade_sprite,fade_level#
  56.                         fade_level# = fade_level# - .01
  57.                         If fade_level# <= 0
  58.                                 fade_level# = 0
  59.                                 fade_in = False
  60.                         EndIf
  61.                 EndIf
  62.                
  63.                 If fade_out = True
  64.                         EntityAlpha fade_sprite,fade_level#
  65.                         fade_level# = fade_level# + .01
  66.                         If fade_level# => 1
  67.                                 fade_level# = 1
  68.                                 done = True
  69.                         EndIf
  70.                 EndIf          
  71.                
  72.                 If GetKey() Or timer >= 500
  73.                         fade_in = False
  74.                         fade_out = True
  75.                 EndIf
  76.                        
  77.                 RenderWorld
  78.  
  79.                 ; foreground 2D (not included in fade)
  80.  
  81.                 Color 255,255,255
  82.                 Text 250,16,"This will not fade!"
  83.  
  84.                 Flip
  85.         Wend   
  86. End Function


Comments : none...

 

SimplePortal 2.3.6 © 2008-2014, SimplePortal