dynamic sprite using a char's graphic as a mask

Started by FortressCaulfield, Tue 24/06/2025 12:49:49

Previous topic - Next topic

FortressCaulfield

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.
"I can hear you! My ears do more than excrete toxic mucus, you know!"

-Hall of Heroes Docent, Accrual Twist of Fate

Crimson Wizard

#1
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
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
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.

SMF spam blocked by CleanTalk