This section deals with the functions relating to sprite assets.

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 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.

Since sprites are an integral part of any game, GameMaker: Studio 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.

Sprite Information

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 Properties.

  1. sprite_get_name
  2. sprite_get_number
  3. sprite_get_width
  4. sprite_get_height
  5. sprite_get_xoffset
  6. sprite_get_yoffset
  7. sprite_get_bbox_bottom
  8. sprite_get_bbox_left
  9. sprite_get_bbox_right
  10. sprite_get_bbox_top
  11. sprite_get_tpe
  12. sprite_get_texture
  13. sprite_get_uvs

Sprite Manipulation

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.

  1. sprite_exists
  2. sprite_add
  3. sprite_replace
  4. sprite_duplicate
  5. sprite_assign
  6. sprite_merge
  7. sprite_create_from_surface
  8. sprite_add_from_surface
  9. sprite_collision_mask
  10. sprite_set_offset
  11. sprite_delete
  12. sprite_set_alpha_from_sprite
  13. sprite_set_cache_size
  14. sprite_set_cache_size_ext
  15. sprite_save
  16. sprite_save_strip

Skeletal Animation

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:

Back: Game Assets
© Copyright YoYo Games Ltd. 2015 All Rights Reserved