/Surfs

A small library for Gamemaker that makes using surfaces easier than ever

Primary LanguageGame Maker LanguageMIT LicenseMIT

SURFS

A library for Gamemaker v2022.5+ that makes using surfaces easier than ever


WHAT IS SURFS

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


SETUP AND USAGE

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.


BUILT IN FUNCTIONS

Note: this does not contain all the functions present within Surfs, but only the ones that should be used.


Surfs(surface name,surface width,surface height,[destroy method,args...])

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


Surfs_set_GargabeMethod(surface name,[destroy method,args...])

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


Surfs_free(surface name)

Frees a surface from memory and removes it from the global map.

  • surface name {string} : the name assigned to the surface


Surfs_exists(surface name)

Checks if a saved surface exists.

  • surface name {string} : the name assigned to the surface


Surfs_get(surface name)

Returns the saved surface.

  • surface name {string} : the name assigned to the surface


Surfs_width(surface name)

Returns the saved surface's width.

  • surface name {string} : the name assigned to the surface


Surfs_height(surface name)

Returns the saved surface's height.

  • surface name {string} : the name assigned to the surface


Surfs_set_target(surface name)

Sets the saved surface as the drawing target.

  • surface name {string} : the name assigned to the surface


Surfs_draw(surface name)

Draws the saved surface.

  • surface name {string} : the name assigned to the surface


Surfs_resize(surface name)

Resizes the saved surface.

  • surface name {string} : the name assigned to the surface


Surfs_get_texture(surface name)

Returns the surface texture's pointer.

  • surface name {string} : the name assigned to the surface


Surfs_debug()

Draws informations related to Surfs.


DESTROY METHODS

Surfs features a couple of destroy methods to tell when to free a surface, but it suggested to use your own custom methods.


"obj", object/[object1,object2..]

Checks if one or more objects exist, and if they don't, the surface is freed.


"region", [surface x,surface y,left,top,right,bottom],inside

Checks if the surface can fit inside a specific region, its rigth and bottom positions are calculated automatically.


Gamemaker's/Custom methods

You can assign any kind of function as a destroy method, the surface will be freed if the method returns true.


SLAP METHODS

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.


ABOUT AND CREDITS

Surfs is licensed under the MIT license

Surfs made by Electro