ID:987210
 
Keywords: alpha, fade, logo
(See the best response by Nadrew.)
Code:
            var/obj/P = new
P.icon='Mob.dmi'
P.screen_loc="2,2"
src.client.screen+=P
var/Palpha=0
while(Palpha!=250)
Palpha+=10
P.icon = rgb(0,0,0,Palpha)
sleep(3)
sleep(40)
while(Palpha!=0)
Palpha-=10
P.icon = rgb(0,0,0,Palpha)
sleep(3)
src.client.screen-=P


Problem description:
So I was wanting a logo to fade in and hold for a few seconds then fade out. I've tried to get it to work but for some reason I just cant do it. Anyone see the problem?
Best response
You're trying to set the icon to a rgb() value, instead of adding/removing the color from the icon.

You may end up finding it easier to just make an icon with the fading states and using that, icon operations for stuff like this tend to be a bit overkill.
The icon is over 255x255 so it would be a real hassle to have to go into paint.NET change alpha, save, go into DM, import, repeat. How is this an overkill?
Also I changed the expressions to += and -= but nothing changed. The icon doesn't even show up.
In response to Ganing
You don't need a whole lot of states since it's just fading, you could probably make it look smooth with 5-6 frames (Probably too many for a simple fade effect still). It's not like PDN has an overly complex method of editing the transparency of an image. It's a lot less hassle in my opinion
Even still... I've noticed that P.icon -= rgb(0,0,0,150) and P.icon += rgb(0,0,0,100) both take away alpha from the icon. Neither add alpha into it. Is this a bug/glitch or is it supposed to be like that?
I've not really used alpha settings with DM, I use paint.net to make any transparency changes. From what you said it seems like instead of adding/subtracting alpha it sets the alpha to the defined value? I'm not sure. I'll look into it
Lemme know if you find anything. I'd rather use this than do a few hours of GFXing.
for the record I now have it like this:
            var/obj/P = new
P.icon='Mob.dmi'
P.screen_loc="2,2"
src.client.screen+=P
var/Palpha=0
P.icon -= rgb(0,0,0,0)
sleep(10)
while(Palpha!=250)
Palpha+=10
P.icon += rgb(0,0,0,Palpha)
sleep(3)
sleep(40)
while(Palpha!=0)
Palpha-=10
P.icon -= rgb(0,0,0,Palpha)
sleep(3)
sleep(40)
src.client.screen-=P
Yeah, it definitely sets the alpha rather than reducing it, what I had done was made a for() loop and changing the value that way. It worked fine but trying to remove the alpha 1 by 1 was just setting it to 1.

        for(var/i=255, 255>0, i--)
if(i < 200)return // The image was completely transparent by this time
src.icon -= rgb(0,0,0,i)
world << i
sleep(1)
Yes that works for going down. But now I can't get the alpha to go back up.
            var/obj/P = new
P.icon='Mob.dmi'
P.screen_loc="2,2"
src.client.screen+=P
for(var/i=150, 150>0,i+=10)
if(i>=250)
return
P.icon += rgb(0,0,0,i)
sleep(3)


This was just a revered version of your code and it did not make the alpha go back up.
In response to Ganing
Ganing wrote:
Yes that works for going down. But now I can't get the alpha to go back up.
>           var/obj/P = new
> P.icon='Mob.dmi'
> P.screen_loc="2,2"
> src.client.screen+=P
> for(var/i=150, 150>0,i+=10)
> if(i>=250)
> return
> P.icon += rgb(0,0,0,i)
> sleep(3)
>

This was just a revered version of your code and it did not make the alpha go back up.

It seems images are completely transparent by the time it hits 200 so if you change it from 150 to 250 it should work.
No what I posted was a version to make the alpha fade in again. I can't get it to fade in again because no matter how I do it for some reason it keeps fading more out.