Dark Bit Factory & Gravity
PROGRAMMING => General coding questions => Topic started by: Pot Noodle on July 29, 2011
-
Hi guys,
I was wondering if anyone can help with this problem I have?
I am trying to fade my screen with opengl Alpha and fade the volume of my music
at the same time but I would like them both to finish at the same time.
Here is my code from my main loop.
If KeyDown(KEY_ESCAPE) Or exitprog Then
exitprog = True
If alpha > 0.7 And vlevel > 0 Then vlevel:-1; BASS_SetVolume(vlevel)
fadescreen()
End If
This is BlitzMax code, Thanks for any help.
-
You haven't posted enough code for anyone to give an exact answer, but let's say you want the fade to last 2 seconds. Let's also say alpha goes from 1->0 and volume goes from 255->0 during the fade.
const fadetime = 2000
fader#=fadetime
...
;main loop
repeat
alpha#=fader/fadetime
volume#=255*fader/fadetime
setvolume(volume)
setalpha(alpha)
fader = fader - elapsedtime
flip
until fader<=0
Jim
-
Hi Jim,
My main loop keeps running even after the Esc key has been pressed.
So it keeps drawing the screen, The alpha channel is set at #0.1 and has to fade to #1.0
The volume of the music on my system is set at int:67 this must dec to 0
On other system this volume may be less or higher depending on the mixer wave setting.
I would like a smooth not to fast fade of music and screen
The alpha controls a black rectangle that fills the screen and fades from transparent to not transparent.
Thanks Jim
-
you just have to interpolate from one value to another
interpolate = firstvalue + curstep*(finalvalue-firstvalue)/numsteps;
-
Thanks rain_storm but you are dealing with an idiot here, Can you elaborate on that please.
What would the first value be?
I guess the finalvalue would be 0 for the volume and 1.0 for the alpha ;D
Thanks for any help on this.
-
interpolation (http://en.wikipedia.org/wiki/Interpolation) is the process of taking a few sample points and trying to fill in the missing points in between, so that the new points transition smoothly from one extreme to the other. The most simple form is linear interpolation (the pseudocode I gave above), in which the points inbetweens fall apon a straight line with both ends being the sample points.
you can use that equation to transition from a given initial colour to a desired colour doesn't have to be black it could just as easily be red or white. It doesn't even have to be colours, anything can be interpolated.
-
Thanks Rain_Storm, I had read that info on the web but I can not get my head around it but I will play with it and see
Cheers for your help.