We are about to switch to a new forum software. Until then we have removed the registration on this forum.
Currently making a rhythm game and I want to create a fade to black/fade out animation for when I switch between the menu and the song selection screen. I also want to use this animation for when I'm trying to pick between songs in the song selection screen.
I know it's not entirely necessary and the game will still work without it, but I kinda wanna make it look prettier. Some ideas/code would be nice!
The animation would kinda look like this:
-fade to black
-change image behind it (hidden from user)
-start playing music of the song selection screen (hidden from user)
-fades out from black with entirely new background/music playing
Answers
@kurtsnafu --
Here is an example sketch demonstrating a timed cross-fade. It is for two videos, but works the same way for two images:
...and here is a more recent discussion on how to program timed fading for different timing sequences:
https://forum.processing.org/two/discussion/comment/96657/#Comment_96657
See also other past discussions:
Please have a look at the mask documentation for PImage in the reference. In your case, you need to setup an array as big as your image. Then you change the value of the array from 255 (fully opaque) to 0 (fully transparent) and then you apply this array to your image via mask() function.
The other extra step is to figure the timing. Trigger event applies mask, then change and apply the mask at some fixed intervals until you get full transparency (background is black).
For curiosity, are you using the default renderer or P2D?
Kf
@jeremydouglass: I'm aware of those threads, most of the ones I've seen after searching were just crossfades between two videos. I've read most of them, but I still cannot wrap my head on how to transition to another gameState while still having a tint/black-rectangle on top of everything. I feel like it is easier on a video because it switches automatically.
@kfrajer: I'm kinda confused by this. So you propose a solution that involves only masking an image? I will be covering up the whole gameState, so that means the whole menu (background, flashing lights, and etc). and not just a single image. Sorry if I'm not getting something.
Thank you for your replies.
@kurtsnafu -- re:
As I said, it works the same with two images as with two videos -- or with two rects -- or with two anything!
The important thing is that a fader is really just this a simple
map()
function wrapped in aconstrain()
call. That's it -- one long line of code. You can use a fader to map anything -- for example, times to transparency levels. Time goes in, alpha color comes out.In the sketch above,
f
is changing thefill()
transparency of two rectangles. However, the fader code has nothing to do with rectangles. Instead offill(255,f); rect()
this could betint(255,t); image()
for an image, or a PGraphics surface, or a movie frame. Or it could be a shape. The fader code is the same -- shift a variable, then use the output as an argument to the change visibility while drawing some object -- any object!Want to add keyboard control? Calculate the
amt
argument based on the last time a key was pressed. Want multiple faders? Call with different sets of arguments. Want something a bit more concise for those sets of arguments? Create a CrossFader class -- this is essentially still just a wrapper around a single line of constrain(map()) code:Now you can initialize a fader and then just call
fader(millis())
orfader()
-- but it is still just a singlemap()
wrapped inconstraint()
.This is my version.
Keywords: Duotransition, timed image transition, fade, fading, fade out fade in
Kf