EVENT ANIMATESPRITES

From EDukeWiki
Jump to navigation Jump to search

EVENT_ANIMATESPRITES is a Game Event.

This event is triggered every time a sprite is displayed on the screen, as long 16 has been added to the mdflags member of the corresponding sprite in the game world. This event can be used to manipulate sprites that are drawn on the screen. Drawn sprites are accessed through the tsprite array, which has its own members separate from the regular actor array. Members of the tsprite array are similar to members of the regular sprite array, but they begin with 'tspr' (E.g., xrepeat becomes tsprxrepeat).

Note that one sprite can be rendered multiple times in the game world, through shadows or mirrors. Sprites with a cstat of 32768 are inaccessible through this event since they are not rendered (rather than merely being turned invisible). For the same reason, setting tsprcstat to 32768 will have no effect.

The game itself use this event for a series of effects: changing the visible palette and/or shade of an actor to that of its sector or when Night Vision Goggles are used; not showing certain sprites depending of the video settings (by setting tsprxrepeat and tspryrepeat to zero); making the player sprites translucent when using third-person view mode; etc. The effects can be different for each player in a multiplayer game.

Example of how to use this event:

  gamevar TEMP 0 0
  actor APLAYER MAXPLAYERHEALTH PSTAND 0 0
  getactor[THISACTOR].mdflags TEMP
  orvar TEMP 16
  setactor[THISACTOR].mdflags TEMP
  // rest of player code

In this first block of code, we add 16 to the mdflags member of the player sprite, so that it will be processed by the ANIMATESPRITES event. Next, is the code for the event:

  onevent EVENT_ANIMATESPRITES
  gettspr[THISACTOR].tsprcstat TEMP
  ifvarand TEMP 2
      xorvar TEMP 2
  settspr[THISACTOR].tsprcstat TEMP
  endevent

The second block of code removes transparency from the player's tsprite, so that when the player is in F7 view mode, the player sprite will appear solid. This effect cannot be achieved by setting the cstat of the player sprite directly. Note that the code will only affect the player sprite, because only the player sprite has had 16 added to its mdflags member.

See gettspr and settspr.