PlayerInfo PSprite methods

From ZDoom Wiki
Jump to navigation Jump to search

PlayerInfo PSprite methods

The following methods are called on a PlayerInfo pointer to set up and interact with PSprites. These methods have to be called on a PlayerInfo pointer. For example, when doing it from a PlayerPawn actor, the prefix for them would be self.player (or just player). Same for calling from a Weapon state or a weapon action function, (since in the context of weapon states self is the player pawn owner, while invoker is the weapon itself).

  • PSprite FindPSprite(int id)
Finds a PSprite instance on the layer id and returns a pointer to it. If it doesn't exists, returns null. This allows modifying a PSprite instance directly, much like various A_Overlay* functions do, and also allows checking that a certain PSprite layer already exists.
  • PSprite GetPSprite(int id)
Same as FindPSprite, but if the PSprite doesn't exist, this function will create it and return a pointer to it.
  • void SetPSprite(int id, State stat, bool pending = false)
Sets the PSprite on the specified layer to the specified state (if the layer doesn't exist, it'll be created first). Basically, combines GetPSprite and SetState.
Generally, this is the same as A_Overlay, with one small difference: if A_Overlay is called on a layer that already exists, it'll reset its offsets before moving to the new state, whereas SetPSprite won't. The latter may be useful when there's a need to move a PSprite layer to a different state while retaining previously set offsets. In addition, this function can be called from anywhere, whereas A_Overlay can only be called from a weapon state or weapon action function.
  • void SetSafeFlash(Weapon weap, State flashstate, int index)
Verifies that flashstate + index exists in the state table of the passed weapon (or a weapon class it inherits from) before setting the PSP_FLASH layer. This is mainly useful for preventing crashes if an offset state isn't guaranteed to exist i.e. a child class overrides it.