The Nine Slice Struct

A Nine Slice struct can be created using sprite_nineslice_create(), or retrieved from a sprite using sprite_get_nineslice(). This struct will contain properties that can be changed and applied to a sprite using sprite_set_nineslice().

If retrieved from a sprite, changing values in this struct will affect the original sprite.

The following properties will be available in this struct:

Nine Slice Struct
VariableTypeDescription
enabledBooleanThis boolean will be true if Nine Slicing is enabled for the sprite, and false if it is disabled. You can modify this to enable or disable Nine Slicing for the sprite.
leftRealThis is the offset for the left guide on the x axis, relative to the left edge of the sprite.
rightRealThis is the offset for the right guide on the x axis, relative to the right edge of the sprite.
topRealThis is the offset for the top guide on the y axis, relative to the top edge of the sprite.
bottomRealThis is the offset for the bottom guide on the y axis, relative to the bottom edge of the sprite.
tilemodeArray of Tile Mode ConstantsThis returns an array containing the Tile Modes for the edge and centre slices.

 

Tile Modes

The Tile Mode of each slice can be read or modified using these constants as the array index:

Nine Slice Edge Constant
ConstantDescription
nineslice_leftThe left edge slice
nineslice_topThe top edge slice
nineslice_rightThe right edge slice
nineslice_bottomThe bottom edge slice
nineslice_centreThe centre slice

The Tile Mode for a slice will be (or can be set to) one of the following constants:

Tile Mode Constant
ConstantDescription
nineslice_stretchThe slice will be stretched
nineslice_repeatThe slice will be repeated
nineslice_mirrorThe slice will be repeated by mirroring
nineslice_blankThe slice will not be stretched or repeated, resulting in a blank area after it
nineslice_hideThe slice will not appear at all

Since tilemode is an array, you need to use the array syntax to change the Tile Mode of a slice. The code example below sets the Tile Mode of the top slice to Repeat:

Example:

var _nineslice = sprite_get_nineslice(spr_box);

_nineslice.tilemode[nineslice_top] = nineslice_repeat;

See this page for more information on the Nine Slice technique.