Author Topic: How to smoothly fadeout desktop?  (Read 4133 times)

0 Members and 1 Guest are viewing this topic.

Offline thesolarcode

  • Newbie
  • Posts: 8
    • View Profile
How to smoothly fadeout desktop?
« on: December 09, 2018, 12:22:34 pm »
For a simple game, I'd like to start it with fading out the desktop.
I have some code which nearly does what I want, but it blinks ugly - maybe someone can help me.

Code: QB64: [Select]
  1.  
  2. screenx = _WIDTH(img&)    
  3. screeny = _HEIGHT(img&)
  4. SCREEN _NEWIMAGE(screenx, screeny, 32)
  5. _PUTIMAGE (0, 0)-(screenx-1, screeny-1), img&
  6.  
  7. ' Fade out
  8. FOR i% = 0 TO 255 STEP 5
  9.   _LIMIT 50                          'control fade speed
  10.   _PUTIMAGE (0, 0)-(screenx-1, screeny-1), img&
  11.   LINE (0, 0)-(screenx-1, screeny-1), _RGBA(0, 0, 0, i%), BF 'increase black box transparency
  12.  

Offline bplus

  • Global Moderator
  • Forum Resident
  • Posts: 8053
  • b = b + ...
    • View Profile
Re: How to smoothly fadeout desktop?
« Reply #1 on: December 09, 2018, 12:59:35 pm »
Why do you have sleep before fadeout?

Never mind.

The blink is the program starting up. It might be less if _limit put after display instead of before ie
update THEN display THEN delay.
« Last Edit: December 09, 2018, 01:15:16 pm by bplus »

Offline thesolarcode

  • Newbie
  • Posts: 8
    • View Profile
Re: How to smoothly fadeout desktop?
« Reply #2 on: December 09, 2018, 01:24:58 pm »
I added the sleep to see where the blinking is happening.
I thought first it blinks due to the program startup, but on my PC there is some ugly blink right after the 3 second sleep (actually it looks like the fade out starts with a black image/screen), and at that time I would guess it is not anymore caused by any startup or setup of the screen.

I tried to move the _limit to after display as you suggested, but don't see any difference.

Offline Pete

  • Forum Resident
  • Posts: 2361
  • Cuz I sez so, varmint!
    • View Profile
Re: How to smoothly fadeout desktop?
« Reply #3 on: December 09, 2018, 01:27:21 pm »
Sometimes my system locks up with _FULLSCREEN, so I tested it this way and added $SCREENHIDE and $SCREENSHOW...

Code: QB64: [Select]
  1. screenx = _WIDTH(img&)
  2. screeny = _HEIGHT(img&)
  3. SCREEN _NEWIMAGE(screenx, screeny, 32)
  4. _SCREENMOVE -5, -25
  5. '_FULLSCREEN
  6. _PUTIMAGE (0, 0)-(screenx - 1, screeny - 1), img&
  7.  
  8. ' Fade out
  9. FOR i% = 0 TO 255 STEP 5
  10.     _LIMIT 50 'control fade speed
  11.     _PUTIMAGE (0, 0)-(screenx - 1, screeny - 1), img&
  12.     LINE (0, 0)-(screenx - 1, screeny - 1), _RGBA(0, 0, 0, i%), BF 'increase black box transparency
  13.     _DISPLAY
  14.  

_SCREENMOVE -5, -25

That statement centers it over my desktop, perfectly at 1366 x 768 desktop resolution. The -25 moves the QB64 title bar off the screen.

Try it with _FULLSCREEN, too. Just unremark it.

Oh, I came back to edit out that _DELAY .1. It turns out it will work without any delay.

Pete
« Last Edit: December 09, 2018, 05:53:02 pm by Pete »
Want to learn how to write code on cave walls? https://www.tapatalk.com/groups/qbasic/qbasic-f1/

Offline bplus

  • Global Moderator
  • Forum Resident
  • Posts: 8053
  • b = b + ...
    • View Profile
Re: How to smoothly fadeout desktop?
« Reply #4 on: December 09, 2018, 01:30:14 pm »
I don't see difference either, I think now it is _FULLSCREEN that causes the blink.

What if you went from black to the image you want, a fade in so the blackout works for you.

Pete's code works better for me.
« Last Edit: December 09, 2018, 01:31:44 pm by bplus »

Offline thesolarcode

  • Newbie
  • Posts: 8
    • View Profile
Re: How to smoothly fadeout desktop?
« Reply #5 on: December 09, 2018, 03:16:41 pm »
Wow, Pete's code works much better, seems like the _FULLSCREEN is the issue.
I can live with the short blink at the start.

Thanks :)

Offline Pete

  • Forum Resident
  • Posts: 2361
  • Cuz I sez so, varmint!
    • View Profile
Re: How to smoothly fadeout desktop?
« Reply #6 on: December 09, 2018, 03:39:48 pm »

Wow, Pete's code works much better, seems like the _FULLSCREEN is the issue.
I can live with the short blink at the start.

Thanks :)


Well, the quote definitely looks better in FULLSCREEN. :D

Pete
Want to learn how to write code on cave walls? https://www.tapatalk.com/groups/qbasic/qbasic-f1/

Offline TempodiBasic

  • Forum Resident
  • Posts: 1792
    • View Profile
Re: How to smoothly fadeout desktop?
« Reply #7 on: December 09, 2018, 06:27:49 pm »
I can confirm Pete experience

this code without _FULLSCREEN  works well with a bit flickering at the start... just a little
in the while with _FULLSCREEN the flickering is like an heartquake!

Code: QB64: [Select]
  1. screenx = _WIDTH(img&)
  2. screeny = _HEIGHT(img&)
  3. SCREEN _NEWIMAGE(screenx, screeny, 32)
  4. _SCREENMOVE -1, -26
  5.  
  6. _PUTIMAGE (0, 0)-(screenx - 1, screeny - 1), img&
  7.  
  8. ' Fade out
  9. FOR i% = 0 TO 255 STEP 5
  10.     _LIMIT 50 'control fade speed
  11.     _PUTIMAGE (0, 0)-(screenx - 1, screeny - 1), img&
  12.     LINE (0, 0)-(screenx - 1, screeny - 1), _RGBA(0, 0, 0, i%), BF 'increase black box transparency
  13.     _DISPLAY
the results seem the same also in this manner...
also my Notebook screen is set to 1366x768 and I need to move screen to -1 , -26 to hide title bar and left border of window.

let me say: Exellent tip Pete!
Programming isn't difficult, only it's  consuming time and coffee

Offline Pete

  • Forum Resident
  • Posts: 2361
  • Cuz I sez so, varmint!
    • View Profile
Re: How to smoothly fadeout desktop?
« Reply #8 on: December 09, 2018, 06:45:27 pm »
Thank you. Some of this non-SCREEN 0 stuff is fun at times. If you're up to some really crazy stuff, have a look at my Firefox session manager app: https://www.qb64.org/forum/index.php?topic=860.0

Pete
Want to learn how to write code on cave walls? https://www.tapatalk.com/groups/qbasic/qbasic-f1/