lua-users home
lua-l archive

[Date Prev][Date Next][Thread Prev][Thread Next] [Date Index] [Thread Index]


On Sunday 18 April 2004 02.32, Steve Randles wrote:
[...]
> if Opacity<=2 then
> step=2;
> end
> if Opacity >=250 then
> step=-2;
> end

(I assume this is inside some sort of event handler or similar, that's 
executed once for each frame to render.)

This is basic programming logic. You need a stop condition, that sets 
step to 0, disables the event handler or whatever.

What you really should do is read up on state machines, IMHO. (I'd use 
step as the state variable in this case, and have three defined 
states; -2: ramping down, 2: ramping up and 0: hold.)

For now, try changing your first condition to something like this:

	if Opacity <= 2 then
		step = 0;
		Opacity = 0;
	end

Now, just set step to 2 and Opacity to something > 2 to initiate the 
in->out fade operation.


//David Olofson - Programmer, Composer, Open Source Advocate

.- Audiality -----------------------------------------------.
|  Free/Open Source audio engine for games and multimedia.  |
| MIDI, modular synthesis, real time effects, scripting,... |
`-----------------------------------> http://audiality.org -'
   --- http://olofson.net --- http://www.reologica.se ---