OverlayID
Jump to navigation
Jump to search
Note: Despite being defined in the Actor class, this function is only meaningful when called from a state handled by PSprite, such as Weapon Ready/Fire/Select/Deselect/etc. state sequences. |
action native int OverlayID()
Usage
Returns the ID of the PSprite layer (aka overlay) used by the state where this function is called. This is convenient when there's a need to call functions like A_OverlayFlags or A_OverlayRenderstyle to modify the current layer.
Return value
- int — the ID of the current layer
Examples
This is a generic example of how OverlayID could be passed to multiple A_Overlay* functions to modify the calling layer:
...
Fire:
WEAP B 2
{
A_FireBullets(5, 3.5, 1, 10);
A_Overlay(100, "MuzzleFlash"); //make a custom muzzle flash layer
}
WEAP BCDE 2;
WEAP A 5 A_ReFire;
goto Ready;
MuzzleFlash:
MUZL A 2 bright
{
A_OverlayFlags(OverlayID(), PSPF_ADDWEAPON|PSPF_ADDBOB, false); //detach from weapon's movement, since muzzle flashes aren't attached to the barrel
A_OverlayOffset(OverlayID(), 0, WEAPONTOP); //move up, so the initial vertical position is aligned with the main layer
A_OverlayFlags(OverlayID(), PSPF_RENDERSTYLE|PSPF_FORCEALPHA, true); //enable renderstyle and alpha change
A_OverlayRenderstyle(OverlayID(), STYLE_ADD); //set additive renderstyle
A_OverlayAlpha(OverlayID(), frandom(0.8, 1.0)); //randomize alpha
}
stop;
OverlayID can also be passed to player.FindPSprite. Below is an alternative implementation of the same behavior, but using FindPSprite. Note, some A_Overlay* functions are still required, because it's not possible to directly modify a PSprite's renderstyle and renderstyle-related flags:
Fire:
WEAP B 2
{
A_FireBullets(5, 3.5, 1, 10);
A_Overlay(100, "MuzzleFlash");
}
WEAP BCDE 2;
WEAP A 5 A_ReFire;
goto Ready;
MuzzleFlash:
MUZL A 2 bright
{
A_OverlayFlags(OverlayID(), PSPF_RENDERSTYLE|PSPF_FORCEALPHA, true); //enable renderstyle and alpha change
A_OverlayRenderstyle(OverlayID(), STYLE_ADD); //set additive renderstyle
PSprite psp = self.player.FindPSprite(OverlayID()); //get a pointer to PSprite that handles the current layer
if (psp)
{
psp.bAddWeapon = false;
psp.bAddBob = false;
psp.y = WEAPONTOP;
psp.alpha = frandom(0.8, 1.0);
}
}
stop;