Asset - Extension Custom sprite framework - memory management and more




Game Maker creates an extra texture page for every sprite and subimage that the user loads into their game using the function sprite_add, this often results in terrible performance issues due to hundreds or sometimes even thousands of texture swaps. This collection of scripts is meant to fix this problem by giving full control over custom texture pages, groups and memory management.

  • Now supports bounding box generation and modification.
  • Supports adding sprites from sheets, subimage files, strips and the internet.
  • Custom texture groups for easier organisation and memory management.
  • Easy texture page creation via an algorithm that does everything, you simply have to specify what to load.
  • Image caches for storing, faster loading and sending texture groups via networking.
  • Functions that can be used the same as the GM sprite functions.
  • All GM built in sprite system drawing functionalities and more.
  • Support for async loading.
Issues & Limitations
This is optimised for YYC and will be pretty much as fast as built in sprite functionality, however, on the regular windows export it will be still be way faster than sprites that were imported using sprite_add but will be a bit slower than built in sprites. This is pure GML so it had to use backgrounds. this means that the memory usage is two times higher than regular sprites. But thanks to the ability to reload and unload anything any time it's quite okay.

Old GMC topic
Last edited by a moderator:
@Braffolk I seems to have ran into a problem
it seems that when I try to load a bunch of images at a time in a while loop the texture page seems to get chopped off

/// @desc load_skins()

var skins = []
var img_group_players = -1;

// Make sure all directorys exist else make them
if (!directory_exists(working_directory+"graphics\\skins")) directory_create(working_directory+"graphics\\skins")

// Find first skin
var skin_name  = file_find_first(working_directory+"graphics\\skins\\*.png", 0)
var skin_index = 0

// Load all skins
while(skin_name != "" && skin_name != "<null>")
    img_group_players  = image_group_create("player_"+string(skin_index));
    image_stream_start(img_group_players, 128, 32, 0);
    image_stream_add(img_group_players, "skin_"+skin_name, working_directory+"graphics\\skins\\"+skin_name, 16, 0, 0);
    skins[skin_index] = image_group_find_image(img_group_players, "skin_"+skin_name);
    skin_name  = file_find_next()
    skin_index ++;

return skins


@Braffolk I seems to have ran into a problem
it seems that when I try to load a bunch of images at a time in a while loop the texture page seems to get chopped off
Sorry for the late reply, that looks like you might have the wrong number of subimages for that sprite.When you have more subimages specified than the sprite actually has, it will end up being chopped into many weird pieces.


The extension has been updated to 2.9.

2.9 changelog:
NOTE: This is a major update. Backup your project before updating. The internal algorithms and the outer scripts have been changed and may potentially cause unintended behaviour - if you find a bug, please report it. Read the changes carefully and update your implementations accordingly. I'm also planning to update this to GMS2 once I buy a license in the end of August.
image_stream_add scripts now require a float between 0.0-1.0 for their origin arguments instead of ints. 1.0 is the width/height of the image to be loaded. This change makes sure that there are no resolution specific limitations by requiring to know the size of the sprite beforehand
  • Added image_save_sheet(ind, fname, row_count) to save images as sheets instead of strips
  • Added image_stream_add_files - creates a single image from subimages saved as multiple files (coin_0.png, coin_1.png etc). The path specified must not contain the file type or the number.
  • Added image_stream_add_sheet - adds an image from a sheet rather than a strip. Requires row and column counts. Shows a warning in case the image size doesn't divide with the row/column counts properly.
  • Image_stream_add_ scripts and image_stream_receive now make sure that the added image is not larger than the texturepage's size.
  • Added bbox support to images. Image streams will now automatically calculate the smallest possible collision box of an added image using Game Maker's built in functionality.
  • Added image_get_bbox_left, _bbox_top, _bbox_right, _bbox_bottom and image_set_bbox
  • Added clamp and removeback booleans to image_stream_start arguments. Clamp cuts the stored image on a texturepage to the bare minimum, getting rid of all the excess transparent sides. Removeback indicates whether to make all pixels with the background colour (left-bottom pixel) transparent.
  • Added image_stream_stop(group) - if the stream is active it will be stopped and all its data cleared from memory.
  • Added image_group_flush(group) - removes the given groups' texturepages from video memory. Read the documentation of background_flush for reference.
  • Added image_group_prefetch(group) - Places the given groups' texturepages into texture memory. Read the documentation of background_prefetch for reference.
  • Removed image_stream_finish_clamp. Use image_stream_start(..., ..., ..., ..., clamp, removeback) instead
  • Made stream debug messages more informative

  • Reorganised majority of the code.
  • Localised the texturepage clamping functionality to image_stream_add scripts.
  • Added 4 internal scripts starting with '__is' to shorten common code in different scripts.
  • Separated image streaming into three types: strip, sheet and list. Each type is handled separately in the stream scripts.
  • Added enum __IS_STREAM_IMAGE to handle image specific stream data.
  • Added enums __ISG_IMG and __ISG_SUBIMG to make image data handling safer and easier to read. All scripts have been updated accordingly.
  • Updated the image format to store bbox data.
  • Updated the cache format from 1.0 to 1.1. The new format also stores bbox values. Image_cache_unpack supports both 1.0 and 1.1 versions, but sets the bbox data to the image size when loading 1.0 caches.
  • Removed "loading_3d" list from image stream. 3D images are now just handled as a __IS.TYPE_3D type in the regular "loading" list