# SPX (Sprite XML) Format External sprite definition file format for the Resource Manager. ## Overview SPX files (`.SPX`) are XML files that define sprite sheet images and their animations in a single file. They are referenced from `resources.xml` via the `` tag. ## Reference in resources.xml ```xml ``` No `name` attribute is needed. The SPX file itself contains named image and sprite resources that become available through the Resource Manager. ## File Format Root element: `` ### Image Tag ```xml ``` | Attribute | Required | Description | |-----------|----------|-------------| | `name` | Yes | Resource name for referencing | | `path` | Yes | PCX file path (relative to SPX file) | | `palette` | No | Name for extracted palette resource | ### Sprite Tag ```xml ``` | Attribute | Required | Description | |------------|----------|-------------| | `name` | Yes | Sprite resource name | | `image` | Yes | Reference to image resource | | `duration` | Yes | Total animation duration in seconds | | `width` | No | Default frame width (pixels) | | `height` | No | Default frame height (pixels) | ### Frame Tag ```xml ``` | Attribute | Required | Description | |------------|----------|-------------| | `x` | Yes | X position in sprite sheet | | `y` | Yes | Y position in sprite sheet | | `width` | No | Frame width (inherits from sprite) | | `height` | No | Frame height (inherits from sprite) | | `offset-x` | No | Drawing offset X (default 0) | | `offset-y` | No | Drawing offset Y (default 0) | | `duration` | No | Per-frame duration in seconds | ## Default Width/Height When `width` and `height` are set on the `` tag, all frames inherit these values. Individual frames can override with their own `width`/`height`. If the sprite has no default size, every frame must specify `width` and `height`. ## Frame Offsets `offset-x` and `offset-y` adjust the drawing position of a frame. This is useful when a frame has a different size than the sprite default: ```xml ``` The attack frames are wider (48px vs 32px default), so `offset-x="-8"` centers them relative to the normal position. When the sprite is flipped horizontally, offsets are automatically negated. ## Per-Frame Duration By default, all frames share the total duration equally (`duration / frame_count`). Individual frames can override this: ```xml ``` When any frame specifies `duration`, the engine switches to variable frame timing: - Frames without explicit duration get `sprite.duration / frame_count` as default - The total animation duration becomes the sum of all frame durations ## Complete Example ```xml ``` ## Path Resolution Image paths in SPX files are relative to the SPX file location, not to `resources.xml`. For example: ``` DATA\ RES.XML <- contains: SPRITES\ PLAYER.SPX <- contains: PLAYER.PCX <- loaded from DATA\SPRITES\PLAYER.PCX ``` ## Usage in Code SPX-loaded sprites are accessed identically to inline sprites: ```pascal ResMan.Init(True); ResMan.LoadFromXML('DATA\RES.XML'); { Sprites from SPX files are available by name } PlayerIdle := ResMan.GetSprite('player_idle'); PlayerRun := ResMan.GetSprite('player_run'); ```