A_OverlayPivotAlign

From ZDoom Wiki
Jump to navigation Jump to search


Note: While the function described on this page is defined in the Actor class, it only works when called either from a PlayerPawn state, or from one of the StateProvider states handled by PSprite, such as Weapon's Ready/Fire/etc. state sequences or a CustomInventory's Use state sequence. It will have no effect in any other context (such as calling it from a weapon's DoEffect override). If there's a need to achieve a similar effect from a different context, obtain a pointer to the necessary PSprite and modify its fields directly.

Actor

action native void A_OverlayPivotAlign(int layer, int halign, int valign)

Usage

Sets the starting alignment to one of the corners of the sprite for the pivot. A_OverlayPivot's offset is applied afterwards. ‎

GZDoom automatically trims empty space of images by default; as a result, when applying rotation/scaling to a sprite animation, even if all sprites in the animation have the same pixel dimensions, the pivot point used for rotation/scaling will be moved around for every sprite if they have different amounts of fully transparent pixels (which is almost always the case between different images). To avoid this, apply NoTrim via ANIMDEFS or TEXTURES to all graphics used in the animation.

Parameters

  • int layer
The layer to modify.
  • int halign
Sets the horizontal alignment corner, which can be one of the following (not combinable). Set to -1 to keep the current alignment.
  • PSPA_LEFT - Default.
  • PSPA_CENTER
  • PSPA_RIGHT
  • int valign
Same as halign but takes the following:
  • PSPA_TOP - Default.
  • PSPA_CENTER
  • PSPA_BOTTOM

Examples

This example shows how the Doom pistol muzzle flash could be modified, assuming you have a custom flash sprite that has a round shape. In this example the flash is drawn below the gun and is randomly scaled and rotated to add variety to its appearance:

Fire:
    PISG A 4;
    PISG B 6 
    {
        A_FireBullets(5.6, 0, 1, 5);
        A_StartSound("weapons/pistol", CHAN_WEAPON);
        A_Overlay(-100, "Flash"); // Draw the flash below the gun rather than above it
    }
    PISG C 4;
    PISG B 5 A_ReFire;
    Goto Ready;
Flash:
    PISG Z 6 bright // Meant to be a custom sprite; doesn't exist in Doom
    {
        A_Light1();
        // Set the pivot point to the center of the sprite:
        A_OverlayPivotAlign(OverlayID(), PSPA_CENTER, PSPA_CENTER);
        // Scale it randomly between 85% and 100% of its
        // size (using 0 for the second argument makes it
        // use the same value as the first one):
        A_OverlayScale(OverlayID(), frandom(0.85, 1), 0);
        // Rotate the sprite randomly:
        A_OverlayRotate(OverlayID(), frandom(0,360));
    }
    TNT1 A 0 A_Light0;
    stop;

See Also