sprite_get_info

This function is used to retrieve information for the given sprite. You supply a sprite index (which can be an asset added through the Asset Browser or a sprite added at runtime)

The function returns a struct with the following variables:

Sprite Info Struct
VariableTypeDescription
widthRealThe sprite's width (in pixels)
heightRealThe sprite's height (in pixels)
xoffsetRealThe sprite's X offset/origin (in pixels)
yoffsetRealThe sprite's Y offset/origin (in pixels)
transparentBooleantrue if the sprite is marked as transparent, otherwise false
(This can only be specified through sprite_add() or similar functions, and will be false for sprites created in the IDE)
smoothBooleantrue if the sprite is marked as smooth, otherwise false
(This can only be specified through sprite_add() or similar functions, and will be false for sprites created in the IDE)
typeRealThe type of the sprite:
0 - Bitmap (Regular sprites)
1 - SWF
2 - Spine
bbox_leftRealPosition of the left edge of the bounding box (in pixels)
bbox_topRealPosition of the top edge of the bounding box (in pixels)
bbox_rightRealPosition of the right edge of the bounding box (in pixels)
bbox_bottomRealPosition of the bottom edge of the bounding box (in pixels)
nameStringThe name of the sprite
num_subimagesRealThe number of sub-images (or frames) in the sprite
use_maskbooleantrue if this sprite uses a collision mask (either generated from a shape or the image itself), otherwise false (meaning it uses a bounding box)
num_masksRealThe number of masks in this sprite (will be greater than 1 if the sprite uses per-frame masks)
rotated_boundsbooleanWhether the mask is "Rectangle with rotation" or not
ninesliceStructThe Nine Slice struct for this sprite, or undefined if it has no nine slice data
messagesArrayArray of broadcast messages for this sprite, where each broadcast message is a struct containing information on the message (more information under "General Sprite Data")
frame_infoArrayArray of frames for this sprite, where each frame is a struct containing information on its timing (more information under "General Sprite Data")
frame_speedRealThe frame speed set for the sprite (see: The Sprite Editor)
frame_typeSprite Speed ConstantThe type of speed set for the sprite, either spritespeed_framespersecond or spritespeed_framespergameframe

This additional variable is available only for Bitmap (regular) sprites:

Sprite Info Struct
VariableTypeDescription
framesArrayArray of frames for this sprite, where each frame is a struct containing information on its texture (more information under "Bitmap Sprite Data")

These additional variables are available only for Spine sprites:

Sprite Info Struct
VariableTypeDescription
num_atlasRealThe number of atlas textures used
atlas_textureArrayArray of texture IDs used for the atlas
premultipliedBooleantrue if this sprite is marked as premultiplied, otherwise false
animation_namesArrayArray containing the names of each animation in this sprite
skin_namesArrayArray containing the names of each skin in this sprite
bonesArrayArray containing structs for each bone in this sprite (more information under "Spine Sprite Data")
slotsArrayArray containing structs for each slot in this sprite (more information under "Spine Sprite Data")

The function will return undefined if the given sprite doesn't exist. Also note that information returned in this struct should be considered read-only as modifying any of these variables will not affect the sprite.

The sections below contain information on the arrays and structs included in the returned struct based on the sprite type:

General Sprite DataGeneral Sprite Data

This section contains information on variables included in the struct for all kinds of sprites.

The messages variable is an array that contains information on the broadcast messages that exist in the given sprite. Each broadcast message in this array is a struct containing the following variables:

Variable NameData TypeDescription
frameRealThe timing of this broadcast message from the start of the animation (in frames)
messageStringThe broadcast message string

The frame_info variable is an array that contains information on the timings of the sprite's frames. Each frame in this array is a struct containing the following variables:

Variable NameData TypeDescription
frameRealThe timing for the start of this frame (in frames)
durationRealThe duration of this frame (in frames)
image_indexRealThe image index of this frame

 

Bitmap Sprite DataBitmap Sprite Data

This section contains information on variables included in the struct for Bitmap sprites (sprites that are not Spine or SWF type sprites).

The frames variable is an array that contains information on the textures of the sprite's frames. Each frame in this array is a struct containing the following variables:

Variable NameData TypeDescription
xRealThe X position of this frame on its texture page (in pixels)
yRealThe Y position of this frame on its texture page (in pixels)
wRealThe logical width of the frame (in pixels) used internally
hRealThe logical height of the frame (in pixels) used internally
textureRealThe texture page ID for this frame
original_widthRealThe original width of the frame (in pixels)
original_heightRealThe original height of the frame (in pixels)
crop_widthRealThe actual width of the frame on the texture page after cropping and scaling (since GameMaker automatically trims the empty space around an image, and also scales it down if it doesn't fit)
crop_heightRealThe actual height of the frame on the texture page after cropping and scaling
x_offsetRealThe X offset from the left edge of the original image to the left edge of the cropped section
y_offsetRealThe Y offset from the top edge of the original image to the top edge of the cropped section

 

Spine Sprite DataSpine Sprite Data

This section contains information on variables included in the struct for Spine sprites.

The bones variable is an array that contains information on all bones in the given Spine sprite. Each bone in this array is a struct containing the following variables:

Variable NameData TypeDescription
parentStringThe name of the parent bone, or undefined if this bone doesn't have a parent
nameStringThe name of this bone
indexRealThe index of this bone
lengthRealThe length of this bone
xRealThe X position of this bone
yRealThe Y position of this bone
rotationRealThe rotation of this bone
scale_xReal(Internal to Spine) Scale value on X
scale_yReal(Internal to Spine) Scale value on Y
shear_xReal(Internal to Spine) Shear value on X
shear_yReal(Internal to Spine) Shear value on Y
transform_modeReal(Internal to Spine) The transform mode

NOTE Please consult the Spine documentation for more information regarding Spine's internal variables.

The slots variable is an array that contains information on all slots in the given Spine sprite. Each slot in this array is a struct containing the following variables:

Variable NameData TypeDescription
nameStringThe name of the slot
indexRealThe index of the slot
boneStringThe name of the slot's bone, or "(none)" if there is no bone for this slot
attachmentStringAttachment name
redRealRed component of the slot's colour (0-1)
greenRealGreen component of the slot's colour (0-1)
blueRealBlue component of the slot's colour (0-1)
alphaRealAlpha component of the slot's colour (0-1)
blend_modeReal(Internal to Spine) Blend mode for the slot
dark_red*RealRed component of the slot's dark colour (0-1)
dark_green*RealGreen component of the slot's dark colour (0-1)
dark_blue*RealBlue component of the slot's dark colour (0-1)
dark_alpha*StringAlpha component of the slot's dark colour (0-1)
attachmentsArray of StringAn array containing the names of all available attachments for this slot.

NOTE The dark colour variables are only available if the slot has Tint Black enabled.

 

 

Syntax:

sprite_get_info(index);

ArgumentTypeDescription
indexSprite AssetThe index of the sprite to get the information for.

 

Returns

Sprite Info Struct (or undefined)

 

Example:

var _info = sprite_get_info(sprite_index);

if (_info != undefined && _info.type == 0)
{
    var _messages = _info.messages;
    var _messageCount = array_length(_messages);
    
    for (var i = 0; i < _messageCount; i ++)
    {
        var _message = _messages[i];
        show_debug_message("Message at frame " + string(_message.frame) + ": " + _message.message);
    }
}

The above code gets the info struct for the instance's sprite, and then checks if it's not undefined and that its type is 0 (meaning that it's a bitmap sprite). In that case, it gets the broadcast message array for that sprite and then runs a for loop to print each broadcast message (along with its frame) to the output log.