A_OverlayPivot

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_OverlayPivot(int layer, double wx = 0.5, double wy = 0.5, int flags = 0)

Usage

Sets the position of the pivot on the overlay. This is used to set a position that will act as the center of rotation for A_OverlayRotate and A_OverlayScale. These offsets are applied on top of A_OverlayPivotAlign's settings.

This function's offsets are affected by A_OverlayFlags's PSPF_PIVOTPERCENT flag, which is set to true by default. Rotates the overlay around the pivot, set by A_OverlayPivot and A_OverlayPivotAlign. ‎

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.
  • double wx
Positive numbers offset to the right. Default is 0.5 (which is center if PSPF_PIVOTPERCENT is applied).
  • double wy
Same as wx but goes down if positive, up if negative instead.
  • int flags
Can be combined with the |:
  • WOF_RELATIVE - Takes into account the current rotation of the overlay.
  • WOF_ADD - The input adds instead of replaces the current offset, and implies WOF_INTERPOLATE.
  • WOF_KEEPX - The 'wx' parameter is ignored.
  • WOF_KEEPY - The 'wy' parameter is ignored.
  • WOF_INTERPOLATE - Enables interpolation for the frame called on. For backwards compatibility however, A_OverlayOffset will override the current interpolation setting if the function is called in the same tic.

Note, despite the default values for wx and wy arguments of the function are 0.5, the default values of the corresponding vector2 pivot field in the PSprite class are 0.0, meaning the default pivot point for overlay rotation and scale is the graphic's top left corner, not its center.

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_OverlayPivot(OverlayID(), 0.5, 0.5);
        // 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