Adventure Game Studio

AGS Support => Beginners' Technical Questions => Topic started by: newwaveburritos on Sun 15/05/2022 19:17:28

Title: Pixel based transparency effect
Post by: newwaveburritos on Sun 15/05/2022 19:17:28
My game is not a true 8 bit game but I do use the sixteen color palette exclusively as as an aesthetic decision.  Thus, using character fade outs and ins kind of feels like cheating to me.  When I import a sprite it has a transparency mask already so I'm wondering if there's a way to randomly replace pixels in the sprite with this transparency mask one by one until the whole sprite is then transparent.  This would look a lot better to my eye than having a character fadeout like from the manual:


int trans = cEgo.Transparency;
while (trans < 100) {
  trans++;
  cEgo.Transparency = trans;
  Wait(1);
}


Thanks, everybody!
Title: Re: Pixel based transparency effect
Post by: FanOfHumor on Sun 15/05/2022 21:13:38
I was interested with your idea so I thought i'd try it.I didn't get it to work the way I was doing it but if you would like to try to get what I have to work here it is.
Code (ags) Select

int pixwide;
int pixheight;
int coverpixelplaced;
function room_AfterFadeIn()
{   

}

function room_RepExec()
{
player.Baseline=-2000;
pixwide = Random(Game.SpriteWidth[2000]);
pixheight=Random(Game.SpriteHeight[2000]);
DynamicSprite* draw;
if(coverpixelplaced==Game.SpriteWidth[2000]||Game.SpriteHeight[2000])
{
//draw.Delete();
//way to make character invisible;
}
else
{
draw=DynamicSprite.CreateFromBackground(0,player.x+pixwide, player.y+pixheight, 1,1 );
coverpixelplaced+=1;
}
}
Title: Re: Pixel based transparency effect
Post by: Khris on Tue 17/05/2022 12:27:07
I made a module:
https://drive.google.com/file/d/1AMUHSUMq_xoszQBP6WUbxCZNVvQb4_7Y/view?usp=sharing

void Character.PixelFade(FadeType fadeType, int width, int speed)

FadeType is eFadeOut or eFadeIn.
width is the width of a single strip of pixels that grows transparent; try a value like 10
speed is the number of frames in between single pixels, use a low number like 3 (smaller number -> faster fading)

(https://i.imgur.com/wfVdqaq.gif)
Title: Re: Pixel based transparency effect
Post by: newwaveburritos on Tue 17/05/2022 17:02:08
Oh wow!  This is amazing and exactly what I meant.  So, I guess that no there is not really an easy way to do it but there is certainly a way.  Thanks so much for putting that together.