Fade IN/OUT

Linux specific forum
andrey2023
New User
New User
Posts: 7
Joined: Mon Mar 06, 2023 5:55 am

Fade IN/OUT

Post by andrey2023 »

Hi!
How to implement fade in\out functions in linux
the ChangeGamma() function does not work on
linux! Here is the code for windows:

Code: Select all

InitSprite()
InitKeyboard() 
OpenScreen(1920, 1080, 16, "Fade In/Out") 
LoadSprite(0, "/home/rndrei/purebasic/examples/sources/Data/PureBasicLogo.bmp")
ChangeGamma(0, 0, 0) 
Repeat 
  ExamineKeyboard() 
Until KeyboardPushed(#PB_Key_All) 
For a = 0 To 255 Step 1 
  ClearScreen(RGB(0,0,0)) 
  ChangeGamma(a, a, a) 
  DisplaySprite(0, 100, 100) 
  FlipBuffers() 
Next a
For b = 255 To 0 Step -1 
  ClearScreen(RGB(0,0,0)) 
  ChangeGamma(b, b, b) 
  DisplaySprite(0, 100, 100) 
  FlipBuffers() 
Next b
End
benubi
Enthusiast
Enthusiast
Posts: 113
Joined: Tue Mar 29, 2005 4:01 pm

Re: Fade IN/OUT

Post by benubi »

You can create an empty "fade-sprite", give it a transparent color other than 0. Or you fill that sprite with Box() and color $010101.

You resize that sprite to the screen size. You can do this once your game started, since it won't be changed.

In your drawing loop you display everything you want to (except the mouse sprite maybe), then use DisplayTransparentSprite() to display the fade-"sprite" with opacity from 0 to 255 for fade in, and 255 to 0 for fade out.

Optionally draw mouse sprite later; I've seen it in point & click adventures. This gives it a more responsive touch among other things imo.
You may also display text like "GAME OVER" or subtitles after the fade in/out. But I digress :)
andrey2023
New User
New User
Posts: 7
Joined: Mon Mar 06, 2023 5:55 am

Re: Fade IN/OUT

Post by andrey2023 »

I took a PNG drawing of a black background 1920x1080, and used it for the dimming effect. But why doesn't this code work?!

Code: Select all

Enumeration
  #Fade
  #Sp1
EndEnumeration
Global b.b=255
If Not InitSprite() Or Not InitKeyboard() Or Not InitMouse() Or Not OpenScreen(1920,1080,16,"")
  MessageRequester("Error", "The can't be initialized",0)
  End
EndIf
UsePNGImageDecoder()
LoadSprite(#Sp1, "/home/rndrei/purebasic/examples/sources/Data/PureBasicLogo.bmp")
LoadSprite(#Fade,"images/backfone1.png")  
Repeat 
    ClearScreen(RGB(0,0,0)) 
    DisplaySprite(#Sp1, 200, 200)    
    StartDrawing(ScreenOutput())
      DrawText(0, 0, "Hello World!", RGB(255,255,255))
    StopDrawing()   
    DisplayTransparentSprite(#Fade,0,0,b)   
    Delay(1)
    FlipBuffers()
    If b=0
     b=255  
    EndIf
    b=b-1
  ExamineKeyboard()
  If KeyboardPushed(#PB_Key_Escape)
    End
  EndIf
ForEver
User avatar
Demivec
Addict
Addict
Posts: 4086
Joined: Mon Jul 25, 2005 3:51 pm
Location: Utah, USA

Re: Fade IN/OUT

Post by Demivec »

andrey2023 wrote: Sun May 21, 2023 8:24 pm I took a PNG drawing of a black background 1920x1080, and used it for the dimming effect. But why doesn't this code work?!
Try loading the #fade sprite like this:

Code: Select all

LoadSprite(#Fade,"images/backfone1.png", #PB_Sprite_AlphaBlending)
Post Reply