Sprites


Sprites are generally the visual representations of objects within the game you are creating, although they can be used for many other purposes. A sprite is either a single image, or a set of images that, when played one after another, looks like a looping animation. Sprites can be created in many formats, with the "traditional" sprite being made up of frames of pixel images, imported into GameMaker Studio 2 as *.png files. However you can also import vector sprites that have been saved in the *.swf format, or skeletal animation sprites that have been saved out as *.json files with accompanying *.atlas and *.png files (for more information on these types of image files and how to import them into GameMaker Studio 2 please see the section Importing Non-Bitmap Sprites).

Since sprites are an integral part of any game, GameMaker Studio 2 has a large number of functions that can be used for getting information about specific sprites, or for changing those that are in your game, or even for loading into an application your own sprites from a source image file.

The following functions can be used to get information about a sprite asset. Please note that these functions get the information from the base sprite (ie. the sprite asset) and not from the sprite as it is being used in an instance. For example, you can use instance variable sprite_width to get the width of the sprite that an instance is using and this width will take into account any scaling that may have been applied. However, if you need to know the width of a sprite as it would be normally, with no transforms applied, you would need to use the sprite_get_width() function below. For more information on the sprite instance variables see the section on Instance Variables.


The functions below are all related to changing the sprite asset (resource) itself. This means that the majority of these functions will affect all instances that reference the sprite being changed, it also means that you must take great care to ensure that a sprite exists before referencing it, or to make sure it is not being referenced before changing it.


These variables are built in to all GameMaker Studio 2 objects and are all related to the sprite assigned to the instance in the room and can be used to change what is drawn and how:


Due to the nature of sprites made using skeletal animation, they also require a sub-set of functions for manipulating the drawn sprite in your games. These functions can be found in the following section of the manual:

  1. Skeletal Animations