Adventure Game Studio

AGS Support => Beginners' Technical Questions => Topic started by: FortressCaulfield on Tue 24/06/2025 12:49:49

Title: dynamic sprite using a char's graphic as a mask
Post by: FortressCaulfield on Tue 24/06/2025 12:49:49
I want a character's sprite to be overlaid with an animated energy effect akin to old cable TV static, but one that is dynamically masked to their body so the static effect plays uninterrupted regardless of what the char is doing. Feels like there should be a way to do this using the char's current graphic as a dynamic sprite mask but I'm not even sure where to start.
Title: Re: dynamic sprite using a char's graphic as a mask
Post by: Crimson Wizard on Tue 24/06/2025 13:24:52
I think "CopyTransparencyMask" is what you need:
https://adventuregamestudio.github.io/ags-manual/DynamicSprite.html#dynamicspritecopytransparencymask

The algorithm approximately is:
1. Create a dynamic sprite from the selected "static" animation frame.
2. Get a number of current character's sprite
Code (ags) Select
ViewFrame* vf = Game.GetViewFrame(ch.View, ch.Loop, ch.Frame);
int charSprite = vf.Graphic;
3. Copy character's sprite transparency mask over to the dynamic sprite:
Code (ags) Select
staticSprite.CopyTransparencyMask(charSprite);
4. Now you have a dynamic sprite with a "static" frame carved as a shape of character's silhouette.
5. Assign this frame to another character following exactly the first one, or as a graphic to a Room Overlay above the character, etc.


EDIT: I was not able to understand, if you want to overlay effect over the character, or completely replace the character with one. The above solution will be same up until the last step.


EDIT 2: in AGS 4.0 this may be now done using object shaders, - I'll leave this note here for the future readers.