TGC Codebase Backup



Fullscreen Image Fade by preyx

2nd Mar 2005 1:48
Summary

Allows you to load and fade in or out any fullscreen-sized image to or from the previous screen. The function automatically determines the fade direction by your start and stop alp



Description

This function takes four arguments, and returns none.
It makes use of the SYNC function, so it comes in really handy with framerate-controlled applications.

I used extremely high sprite and image numbers in order to avoid conflict with any of your own graphics. The high priority number is to ensure that it fades out all objects on the screen.

* NOTE: alpha=255 is opaque and alpha=0 is transparent.
* WARNING: THERE IS NO ERROR CHECKING! Always double-check your inputs.

Example code:
...
`Fade black -> title 1 -> title 2
LOAD IMAGE "media\title1.png", 1, 1
PASTE IMAGE 1, 0, 0
Fade("media\fader\black.png", 255, 0, 4)
WAIT 500
LOAD IMAGE "media\title2.png", 1, 1
PASTE IMAGE 1, 0, 0
Fade("media\title1.png", 255, 0, 8)
...



Code
                                    ` This code was downloaded from The Game Creators
                                    ` It is reproduced here with full permission
                                    ` http://www.thegamecreators.com
                                    
                                    `Fullscreen Image Fade by Bryan Yang
`filename$: in same format as "LOAD IMAGE" function (string)
`starta: the starting alpha value (0-255)
`stopa: the stopping alpha value (0-255)
`rate: the change in alpha value per cycle (rate > 0)
`NOTE: alpha=255 is opaque and alpha=0 is transparent.
`WARNING: NO ERROR CHECKING! Always double-check your inputs.

FUNCTION Fade(filename$, starta, stopa, rate)
GET IMAGE 1001, 0, 0, SCREEN WIDTH(), SCREEN HEIGHT(), 1
LOAD IMAGE filename$, 1000
SPRITE 1000, 0, 0, 1000
SET SPRITE 1000, 0, 1
SET SPRITE PRIORITY 1000, 1000
a = starta
IF starta > stopa
r = -rate
ELSE
r = rate
ENDIF
REPEAT
SET SPRITE ALPHA 1000, a
PASTE IMAGE 1001, 0, 0, 0
a = a + r
SYNC
UNTIL (r>0 AND a>stopa) OR (r<0 AND a<stopa)
SET SPRITE ALPHA 1000, stopa
PASTE IMAGE 1001, 0, 0, 0
SYNC
ENDFUNCTION