Adventure Game Studio | Forums

AGS Support => Beginners' Technical Questions => Topic started by: newwaveburritos on 15 May 2022, 19:17

Title: Pixel based transparency effect
Post by: newwaveburritos on 15 May 2022, 19:17
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:

Code: [Select]
int trans = cEgo.Transparency;
while (trans < 100) {
  cEgo.Transparency = trans;

Thanks, everybody!
Title: Re: Pixel based transparency effect
Post by: FanOfHumor on 15 May 2022, 21:13
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: Adventure Game Studio
  1. int pixwide;
  2. int pixheight;
  3. int coverpixelplaced;
  4. function room_AfterFadeIn()
  5. {  
  7. }
  9. function room_RepExec()
  10. {
  11.         player.Baseline=-2000;
  12.         pixwide = Random(Game.SpriteWidth[2000]);
  13.         pixheight=Random(Game.SpriteHeight[2000]);
  14.         DynamicSprite* draw;
  15.         if(coverpixelplaced==Game.SpriteWidth[2000]||Game.SpriteHeight[2000])
  16.         {
  17.                 //draw.Delete();
  18.                 //way to make character invisible;
  19.         }      
  20.         else
  21.         {
  22.                 draw=DynamicSprite.CreateFromBackground(0,player.x+pixwide, player.y+pixheight, 1,1 );
  23.                 coverpixelplaced+=1;
  24.         }
  25. }
Title: Re: Pixel based transparency effect
Post by: Khris on 17 May 2022, 12:27
I made a module:

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)

Title: Re: Pixel based transparency effect
Post by: newwaveburritos on 17 May 2022, 17:02
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.