A library for Gamemaker v2022.5+ that makes using surfaces easier than ever
Surfs is a library made for Gamemaker v2022.5+ that handles all the boring and monotonous parts of using surfaces in Gamemaker, with only a few simple functions and no need
to use multiple events or extra variables.
Here's what the library can do:
- Handle the creation of surfaces and recreation in case they are gone in a single function
- All surfaces are saved in a global map and can be accessed with only a string, without the need to create new variables for every surface
- You can define when a surface will be freed from memory the moment you create it with built in or custom methods
- Freeing surfaces from memory in the draw event won't cause memory leaks to occur
- The library contains many functions to quickly handle surfaces
Setting up Surfs is super easy, simply download the yymps ,
open your project, drag the yymps into Gamemaker and import everything, and you're done! Surfs automatically initialises itself right before the game starts.
To create a surface with Surfs, you'll need to use the Surfs() function.
Surfs(surface name,surface width,surface height,[destroy method,args]);
- surface name {string} : the name you'll assign to the surface
- surface width {real} : the width of the surface
- surface height {real} : the height of the surface
- destroy method {string, function} : this determines when the surface will be freed from memory, it can either be a built in Surfs method, a built in Gamemaker method, or a custom function.
- args {any}: this can either be one value or an array of values, these are the arguments that will be used by the destroy method
This function can be put right before you draw the surface, the surface will only be created when it doesn't exist.
Surfs comes with many built-in functions where you only need to the surface's name to use it, but you can always use Surfs_get(surface name)
in case you need to use the surface in other parts of your code.
Note: this does not contain all the functions present within Surfs, but only the ones that should be used.
Creates a new surface and assigns it to the global map if it doesn't exist.
- surface name {string} : the name you'll assign to the surface
- surface width {real} : the width of the surface
- surface height {real} : the height of the surface
- destroy method {string, function} : this determines when the surface will be freed from memory, it can either be a built in Surfs method, a built in Gamemaker method, or a custom function.
- args {any}: this can either be one value or an array of values, these are the arguments that will be used by the destroy method
Assigns a new destroy method to an existing surface.
- surface name {string} : the name assigned to the surface
- destroy method {string, function} : this determines when the surface will be freed from memory, it can either be a built in Surfs method, a built in Gamemaker method, or a custom function.
- args {any}: this can either be one value or an array of values, these are the arguments that will be used by the destroy method
Frees a surface from memory and removes it from the global map.
- surface name {string} : the name assigned to the surface
Checks if a saved surface exists.
- surface name {string} : the name assigned to the surface
Returns the saved surface.
- surface name {string} : the name assigned to the surface
Returns the saved surface's width.
- surface name {string} : the name assigned to the surface
Returns the saved surface's height.
- surface name {string} : the name assigned to the surface
Sets the saved surface as the drawing target.
- surface name {string} : the name assigned to the surface
Draws the saved surface.
- surface name {string} : the name assigned to the surface
Resizes the saved surface.
- surface name {string} : the name assigned to the surface
Returns the surface texture's pointer.
- surface name {string} : the name assigned to the surface
Draws informations related to Surfs.
Surfs features a couple of destroy methods to tell when to free a surface, but it suggested to use your own custom methods.
Checks if one or more objects exist, and if they don't, the surface is freed.
Checks if the surface can fit inside a specific region, its rigth and bottom positions are calculated automatically.
You can assign any kind of function as a destroy method, the surface will be freed if the method returns true.
Slap methods let you apply things to a Surf right after it's created, this is useful for surfaces that are mostly static.
However, because of how surfaces work, it's recommended to only use it on surfaces with non moving elements, so be mindful about that.
Surfs is licensed under the MIT license
Surfs made by Electro