PDA

View Full Version : Fading Images



PaulW
11-18-2003, 09:19 AM
Hi all. I am trying to perfect a fade effect. So far I have the following:

On show:

opacity = 100;
Page.StartTimer(1);


On Timer:

opacity = opacity - 2;
Image.SetOpacity("Photo", 100 - opacity);
y = 0
if (opacity < y) then
Page.Jump("Menu")
end

I am very new to the use of scripting so I took some of the above from an example that Corey posted. I have changed it a bit because I am trying to get a very smooth fade in then a page jump when the image is fully visible.

The problem I am finding is that I cannot get the image to fade in quickly and smoothly. When I try to increase the speed that the picture apears, I end up with a poor stepped fade. It is not smooth.

Does anyone know of a better way that will produce a smooth fade?

Maybe I could try using two of the same image with different opacity settings.

Any help or suggestions appreciated.

Worm
11-18-2003, 09:31 AM
I have had good results doing almost the same as you. I use this to fade in and out a tooltips text when I mouse over a button or image.



OnAppLoad:
sFade="";
Page.StartTimer(2);


OnMouseEnter:
sFade="UP";

OnMouseExit:
sFade="DOWN";


On Timer Event:
if sFade=="UP" then
if Image.GetOpacity("imgToolTip") ~= 100 then
Image.SetOpacity("imgToolTip", Image.GetOpacity("imgToolTip") + 3);
end
end

if sFade=="DOWN" then
if Image.GetOpacity("imgToolTip") ~= 0 then
Image.SetOpacity("imgToolTip", Image.GetOpacity("imgToolTip") - 3);
end
end

PaulW
11-18-2003, 10:48 AM
Hi Worm, thanks for your reply. I have changed my script to the following:

On Show:

Page.StartTimer(1);


On Timer:

Image.GetOpacity("Photo");
Image.SetOpacity("Photo", Image.GetOpacity("Photo") + 3);
if Image.GetOpacity("Photo") == 100 then
Page.Jump("Menu");
end

I think your method simplifies things a bit. However, I still find the fade is not particularly smooth. I am using the fade on a large image and I would imagine the change between opacity values is more noticable.

I think I will go with the above script as I cannot see a way to smooth the fade.

Worm
11-18-2003, 10:59 AM
You could use a loop too. Bad side is the app is basically sleeping until the loop finishes.

Also, in your last post you're comparing your variable to 100 and steping by 3, you might better change that to a >= ;)



-- A for loop that counts from 0 to 100 in 2's
min = 0; -- The number to start at
max = 100; -- The number to stop at
step = 2; -- The number to count by (in this case 0, 2, 4, ...)
for count = min, max, step do
-- Do something here
Image.SetOpacity("Photo", count);
end

PaulW
11-18-2003, 11:26 AM
Hey Worm, good point with the >= :D .

Maybe I'll use 2 or 4 as a step.

I tried your loop. Seemed to get a very similar results to the original method. Thanks for the suggestion though.