fading the screen like a transition

Started by wadmixfm, February 24, 2024, 12:22:33

Previous topic - Next topic

wadmixfm

Hello fellow Syntaxians :)


Ok i have seen some example code in the search that grabs the screen with grab image commands
then it fades in or out by changing the ink colors setcolor bla bla bla

is there a more direct approach without grabbing images or setting the ink color ?

i want to use a sort of transition from one page to the next i thought that fading from one to the other
has a nice touch.

cheers

lee

Midimaster

No need for grabbing...

Simply use SetAlpha for the coming image:

Graphics 800,600
SetBlend ALPHABLEND
Global A:Double = 0.001
....
Repeat
    SetAlpha 1
    DrawImage GoingImage,0,0
    SetAlpha A
    DrawImage ComingImage,0,0
    A = A*1.01 ' speed of swapping
    If A>1 Then A=1
    Flip
Until AppTerminate()
...back from Egypt

Derron

#2
If the "page" is dynamically constructed or animated (text/letters fading in etc) things do not work by simply setting the "alpha" for the draw commands.

Just think of what happens if you set the alpha here:

'old page
SetAlpha 1.0 - FadeProcess
DrawBackgroundImage(1)
DrawText(1)
DrawMagicParticles(1)

'new page
SetAlpha FadeProgress
DrawBackgroundImage(2)
DrawText(2)
DrawMagicParticles(2)


The "Text" and the Particles would be semi-translucent and the background image too - but their "merged" alpha would be bigger - as if you paint with water paint on top of each other.


This is where "renderimage" comes in handy. Render your "page" into the a renderimage - and then draw these renderimages with the alpha you want (or whatever transition you plan to do).
This also allows stuff like "scaling to 0 while whirling" (these newspaper-swirl-effects like in the old super hero series/movies).

Local renderimage:TRenderImage = CreateRenderImage(w, h)

Repeat
  SetRenderImage(renderimage)
  Cls 'clean the renderimage from old content
  DrawXYZ() 'draw new stuff on it

  SetRenderImage() 'draw to backbuffer again
  SetAlpha 0.5 * (1 + sin(Millisecs() * 0.1))
  DrawImage(renderimage, MouseX(), MouseY()) 'draw the renderimage content on the screen
  SetAlpha 1.0
  Flip
Until KeyHit(KEY_ESCAPE) or AppTerminate()
(untested - just typed in code)

there is an example I made a while ago (maybe I should add some examples to the docs too ...)
https://github.com/GWRon/brl.mod-NG/issues/2

tried to capture the "shining through" effect you would see when simply drawing things on top of each other with alpha < 1.0.



bye
Ron

wadmixfm

oh right

Thanks for the fast replies guys :)

lee

will give it a try :)