diff --git a/Manual/contents/GameMaker_Language/GML_Reference/Asset_Management/Instances/Instance_Variables/depth.htm b/Manual/contents/GameMaker_Language/GML_Reference/Asset_Management/Instances/Instance_Variables/depth.htm index 666059a8b..6c9b5a5b2 100644 --- a/Manual/contents/GameMaker_Language/GML_Reference/Asset_Management/Instances/Instance_Variables/depth.htm +++ b/Manual/contents/GameMaker_Language/GML_Reference/Asset_Management/Instances/Instance_Variables/depth.htm @@ -1,58 +1,60 @@ - + -
- -When you create an object you can assign it an initial depth which defines how the instances of that object will be drawn in the room when the game is being played and this variable can be used to get and to change that depth value while the game is running. You would normally not need to use this variable as you should be setting instances to be added to discreet layers, which in turn are set to a specific depth, but it may be that you want to change the depth of an instance using this value, in which case a "temporary layer" will be created specifically for the instance at the given depth. Note that when no instances are on the same depth then this temporary layer will be removed from memory (unlike regular layers which will remain even if they have nothing on them).
-When you modify the depth variable and GameMaker manages the layers, the built-in layer variable will return -1 and not the layer handle, since managed layers cannot be manipulated through code.
-In GameMaker the lower the depth value for an instance, the "closer to the camera" that instance will be drawn, while a higher depth value means that the instance will be drawn "further away from the camera", i.e: -1000 is drawn on top of -100, which is drawn on top of 0, and so on.
-Note that instances that have the same depth may be drawn above or below one another regardless of how it appears in The Room Editor. This is not guaranteed to be consistent between target platforms as it will depend on the graphics device in use. If you want to guarantee that something is drawn over or under everything else, you should always set the depth (or layer) explicitly.
-Also note that there is a minimum (-16000) and maximum (16000) depth value outside of which instances will not be drawn, although they will still exist and process events.
-The minimum and maximum depth values are approximate. As a result, when you set the draw depth to a value close to these limits, what you're drawing might not be drawn.
-You cannot set the depth of an instance in its Draw event (all other events are fine). You can, however, set the depth at which to draw things in the Draw event using gpu_set_depth.
-Keep in mind that modifying the depth of an instance may change which Filters & Effects are applied on it, as changing the depth to be lower than an FX layer's depth will no longer apply its effect on the instance.
--
depth
--
Real (single precision floating point value)
--
if (y != yprevious)
-
- {
-
- depth = -y;
-
- }
The above code will check to see if the y position has changed and if it has then the depth will also be set to correspond to it.
--
-
When you create an object you can assign it an initial depth which defines how the instances of that object will be drawn in the room when the game is being played and this variable can be used to get and to change that depth value while the game is running. You would normally not need to use this variable as you should be setting instances to be added to discreet layers, which in turn are set to a specific depth, but it may be that you want to change the depth of an instance using this value, in which case a "temporary layer" will be created specifically for the instance at the given depth. Note that when no instances are on the same depth then this temporary layer will be removed from memory (unlike regular layers which will remain even if they have nothing on them).
+When you modify the depth + variable and GameMaker manages the layers, the built-in layer variable will return -1 and not the layer handle, since managed layers cannot be manipulated through code. +
+In GameMaker the lower the depth value for an instance, the "closer to the camera" that instance will be drawn, while a higher depth value means that the instance will be drawn "further away from the camera", i.e: -1000 is drawn on top of -100, which is drawn on top of 0, and so on.
+Note that instances that have the same depth may be drawn above or below one another regardless of how it appears in The Room Editor. This is not guaranteed to be consistent between target platforms as it will depend on the graphics device in use. If you want to guarantee that something is drawn over or under everything else, you should always set the depth (or layer) explicitly.
+Also note that there is a minimum (-16000) and maximum (16000) depth value outside of which instances will not be drawn, although they will still exist and process events.
+The minimum and maximum depth values are approximate. As a result, when you set the draw depth to a value close to these limits, what you're drawing might not be drawn.
+You cannot set the depth of an instance in its Draw event (all other events are fine). You can, however, set the depth at which to draw things in the Draw event using gpu_set_depth.
+Keep in mind that modifying the depth of an instance may change which Filters & Effects are applied on it, as changing the depth to be lower than an FX layer's depth will no longer apply its effect on the instance.
++
depth
++
Real (single precision floating point value)
++
if (y != yprevious)
+ {
+ depth = -y;
+ }
The above code will check to see if the y position has changed and if it has then the depth will also be set to correspond to it.
++
+
This function will destroy the given background element. You supply the background ID (which you get when you create the background using layer_background_create() or when you use the layer handle along with layer_get_background_id()) and this will remove it. Note that this does not remove the layer, only the background from it, and if the background is one that has been added in the room editor, then the next time you leave the room and then return, the background will be recreated again. However if the room is persistent, the background will be removed unless room persistence is switched off again.
--
layer_background_destroy(background_element_id)
-Argument | -Type | -Description | -
---|---|---|
background_element_id | -Background Element ID | -The unique ID value of the background element to be destroyed | -
-
N/A
--
var lay_id = layer_get_id("Background_trees");
-
- var bck_id = layer_background_get_id("Forrest");
-
- if (layer_background_exists(lay_id, bck_id))
-
- {
-
- layer_background_destroy(bck_id);
-
- }
The above code checks the layer "Background_trees" to see if the given background element exists and if it does, then it is destroyed (but not the layer).
--
-
-
This function will destroy the given background element. You supply the background ID (which you get when you create the background using layer_background_create() or when you use the layer handle along with layer_get_background_id()) and this will remove it. Note that this does not remove the layer, only the background from it, and if the background is one that has been added in the room editor, then the next time you leave the room and then return, the background will be recreated again. However if the room is persistent, the background will be removed unless room persistence is switched off again.
++
layer_background_destroy(background_element_id)
+Argument | +Type | +Description | +
---|---|---|
background_element_id | +Background Element ID | +The unique ID value of the background element to be destroyed | +
+
N/A
++
var lay_id = layer_get_id("Background_trees");
+ var bck_id = layer_background_get_id("Forrest");
+
+ if (layer_background_exists(lay_id, bck_id))
+ {
+ layer_background_destroy(bck_id);
+ }
+
The above code checks the layer "Background_trees" to see if the given background element exists and if it does, then it is destroyed (but not the layer).
++
+
+
You can use this function to check and see if a background element exists on any given layer. You supply the layer handle (which you get when you create the layer using layer_create()) or the layer name (as a string - this will have a performance impact) and the background element ID (which you get when you create a background element using layer_background_create() or when you use the function layer_background_get_id()) and the function will return either true if the element exists, or false if it does not.
-This function works within the scope of the current target room - by default the room in which the function is called - which can be set using the function layer_set_target_room().
--
layer_background_exists(layer_id, background_element_id)
-Argument | -Type | -Description | -
---|---|---|
layer_id | -String or Layer ID | -The handle of the layer to target (or the layer name as a string) | -
background_element_id | -Background Element ID | -The unique ID value of the background element to check | -
-
-
var lay_id = layer_get_id("Background_trees");
-
- if (layer_background_exists(lay_id, global.TreesBackground))
-
- {
-
- layer_background_destroy(lay_id, global.TreesBackground);
-
- }
The above code checks the layer "Background_trees" to see if the given background element exists and if it does, then it is destroyed (but not the layer).
--
-
-
You can use this function to check and see if a background element exists on any given layer. You supply the layer handle (which you get when you create the layer using layer_create()) or the layer name (as a string - this will have a performance impact) and the background element ID (which you get when you create a background element using layer_background_create() or when you use the function layer_background_get_id()) and the function will return either true if the element exists, or false if it does not.
+This function works within the scope of the current target room - by default the room in which the function is called - which can be set using the function layer_set_target_room().
++
layer_background_exists(layer_id, background_element_id)
+Argument | +Type | +Description | +
---|---|---|
layer_id | +String or Layer | +The handle of the layer to target (or the layer name as a string) | +
background_element_id | +Background Element ID | +The unique ID value of the background element to check | +
+
+
var lay_id = layer_get_id("Background_trees");
+ if (layer_background_exists(lay_id, global.TreesBackground))
+
+ {
+ layer_background_destroy(lay_id, global.TreesBackground);
+ }
+
The above code checks the layer "Background_trees" to see if the given background element exists and if it does, then it is destroyed (but not the layer).
++
+
+
This function can be used to get the alpha value of the background element. You give the background element ID (which you get when you create a background element using layer_background_create() or when you use the function layer_background_get_id()), and the function will return a value between 0 (fully transparent) and 1 (fully opaque).
--
layer_background_get_alpha(background_element_id);
-Argument | -Type | -Description | -
---|---|---|
background_element_id | -- | The unique ID value of the background element to get the information from | -
-
(from 0 to 1)
--
var lay_id = layer_get_id("Background_sky");
-
- var back_id = layer_background_get_id(lay_id);
-
- if (layer_background_get_alpha(back_id) < 0.1)
-
- {
-
- layer_background_destroy(back_id);
-
- }
The above code will get the layer handle for the layer named "Background_sky" and then use that to get the ID of the background element on that layer. This ID is then used to check the element alpha and if it is less than 0.1, then the layer element is destroyed.
--
-
-
This function can be used to get the alpha value of the background element. You give the background element ID (which you get when you create a background element using layer_background_create() or when you use the function layer_background_get_id()), and the function will return a value between 0 (fully transparent) and 1 (fully opaque).
++
layer_background_get_alpha(background_element_id);
+Argument | +Type | +Description | +
---|---|---|
background_element_id | +Background Element ID | +The unique ID value of the background element to get the information from | +
+
Real (from 0 to 1)
++
var lay_id = layer_get_id("Background_sky");
+ var back_id = layer_background_get_id(lay_id);
+
+ if (layer_background_get_alpha(back_id) < 0.1)
+ {
+ layer_background_destroy(back_id);
+ }
+
The above code will get the layer handle for the layer named "Background_sky" and then use that to get the ID of the background element on that layer. This ID is then used to check the element alpha and if it is less than 0.1, then the layer element is destroyed.
++
+
+
This function can be used to get the blend colour of the background element. You give the background element ID (which you get when you create a background element using layer_background_create() or when you use the function layer_background_get_id()), and the function will return real value that represents the colour assigned.
--
layer_background_get_blend(background_element_id);
-Argument | -Type | -Description | -
---|---|---|
background_element_id | -- | The unique ID value of the background element to get the information from | -
-
Colour Constant
--
var lay_id = layer_get_id("Background_sky");
-
- var back_id = layer_background_get_id(lay_id);
-
- if (layer_background_get_blend(back_id) == c_white)
-
- {
-
- layer_background_blend(back_id, make_colour_rgb(random(255), random(255), 255));
-
- }
The above code will get the layer handle for the layer named "Background_sky" and then use that to get the ID of the background element on that layer. This ID is then used to check the element blend colour and if it is equivalent to the constant c_white, then the layer blend is set to a random colour.
--
-
-
This function can be used to get the blend colour of the background element. You give the background element ID (which you get when you create a background element using layer_background_create() or when you use the function layer_background_get_id()), and the function will return real value that represents the colour assigned.
++
layer_background_get_blend(background_element_id);
+Argument | +Type | +Description | +
---|---|---|
background_element_id | +Background Element ID | +The unique ID value of the background element to get the information from | +
+
+
var lay_id = layer_get_id("Background_sky");
+ var back_id = layer_background_get_id(lay_id);
+
+ if (layer_background_get_blend(back_id) == c_white)
+ {
+ layer_background_blend(back_id, make_colour_rgb(random(255), random(255), 255));
+ }
+
The above code will get the layer handle for the layer named "Background_sky" and then use that to get the ID of the background element on that layer. This ID is then used to check the element blend colour and if it is equivalent to the constant c_white, then the layer blend is set to a random colour.
++
+
+
This function can be used to find out if the background element is tiled horizontally or not. You give the background element ID (which you get when you create a background element using layer_background_create() or when you use the function layer_background_get_id()), and the function will return either true if the element is currently tiled, or false if it is not.
--
layer_background_get_htiled(background_element_id);
-Argument | -Type | -Description | -
---|---|---|
background_element_id | -- | The unique ID value of the background element to get the information from | -
-
-
-
var lay_id = layer_get_id("Background_sky");
-
- var back_id = layer_background_get_id(lay_id);
-
- if (!layer_background_get_htiled(back_id))
-
- {
-
- layer_background_htiled(back_id, true);
-
- }
The above code will get the layer handle for the layer named "Background_sky" and then use that to get the ID of the background element on that layer. This ID is then used to check if the element is tiling across the horizontal axis, and if it is not then it is set to do so.
--
-
-
This function can be used to find out if the background element is tiled horizontally or not. You give the background element ID (which you get when you create a background element using layer_background_create() or when you use the function layer_background_get_id()), and the function will return either true if the element is currently tiled, or false if it is not.
++
layer_background_get_htiled(background_element_id);
+Argument | +Type | +Description | +
---|---|---|
background_element_id | +Background Element ID | +The unique ID value of the background element to get the information from | +
+
+
var lay_id = layer_get_id("Background_sky");
+ var back_id = layer_background_get_id(lay_id);
+
+ if (!layer_background_get_htiled(back_id))
+ {
+ layer_background_htiled(back_id, true);
+ }
+
The above code will get the layer handle for the layer named "Background_sky" and then use that to get the ID of the background element on that layer. This ID is then used to check if the element is tiling across the horizontal axis, and if it is not then it is set to do so.
++
+
+
This function can be used to get the current image index value of the background element. You give the background element ID (which you get when you create a background element using layer_background_create() or when you use the function layer_background_get_id()), and the function will return real value that represents the image index being shown for the sprite. The function will return -1 if either the background element doesn't exist or the element doesn't have a valid sprite assigned to it.
--
layer_background_get_index(background_element_id);
-Argument | -Type | -Description | -
---|---|---|
background_element_id | -- | The unique ID value of the background element to get the information from | -
-
Real (the current sprite image index or -1)
--
var lay_id = layer_get_id("Background_sky");
-
- var back_id = layer_background_get_id(lay_id);
-
- if (layer_background_get_index(back_id) < 4)
-
- {
-
- layer_background_index(back_id, 4);
-
- }
The above code will get the layer handle for the layer named "Background_sky" and then use that to get the ID of the background element on that layer. This ID is then used to check if the image index for the element is less than 4, and if so it is set to 4.
--
-
-
This function can be used to get the current image index value of the background element. You give the background element ID (which you get when you create a background element using layer_background_create() or when you use the function layer_background_get_id()), and the function will return real value that represents the image index being shown for the sprite. The function will return -1 if either the background element doesn't exist or the element doesn't have a valid sprite assigned to it.
++
layer_background_get_index(background_element_id);
+Argument | +Type | +Description | +
---|---|---|
background_element_id | +Background Element ID | +The unique ID value of the background element to get the information from | +
+
Real (the current sprite image index or -1)
++
var lay_id = layer_get_id("Background_sky");
+ var back_id = layer_background_get_id(lay_id);
+ if (layer_background_get_index(back_id) < 4)
+ {
+ layer_background_index(back_id, 4);
+ }
The above code will get the layer handle for the layer named "Background_sky" and then use that to get the ID of the background element on that layer. This ID is then used to check if the image index for the element is less than 4, and if so it is set to 4.
++
+
+
This function can be used to get the current speed multiplier value of the background element. You give the background element ID (which you get when you create a background element using layer_background_create() or when you use the function layer_background_get_id()), and the function will return real value that represents the speed multiplier being used to animate the sprite. Default value is 1.
--
layer_background_get_speed(background_element_id);
-Argument | -Type | -Description | -
---|---|---|
background_element_id | -- | The unique ID value of the background element to get the information from | -
-
-
-
var lay_id = layer_get_id("Background_sky");
-
- var back_id = layer_background_get_id(lay_id);
-
- if (layer_background_get_speed(back_id) > 0)
-
- {
-
- layer_background_speed(back_id, 0);
-
- }
The above code will get the layer handle for the layer named "Background_sky" and then use that to get the ID of the background element on that layer. This ID is then used to check the animation speed for the element and if it is greater than 0, it is set to 0.
--
-
-
This function can be used to get the current speed multiplier value of the background element. You give the background element ID (which you get when you create a background element using layer_background_create() or when you use the function layer_background_get_id()), and the function will return real value that represents the speed multiplier being used to animate the sprite. Default value is 1.
++
layer_background_get_speed(background_element_id);
+Argument | +Type | +Description | +
---|---|---|
background_element_id | +Background Element ID | +The unique ID value of the background element to get the information from | +
+
+
var lay_id = layer_get_id("Background_sky");
+ var back_id = layer_background_get_id(lay_id);
+ if (layer_background_get_speed(back_id) > 0)
+ {
+ layer_background_speed(back_id, 0);
+ }
The above code will get the layer handle for the layer named "Background_sky" and then use that to get the ID of the background element on that layer. This ID is then used to check the animation speed for the element and if it is greater than 0, it is set to 0.
++
+
+
This function can be used to get the current sprite of the background element. You give the background element ID (which you get when you create a background element using layer_background_create() or when you use the function layer_background_get_id()), and the function will return a handle that represents the sprite index being shown. If the element has no sprite assigned, the function will return -1.
--
layer_background_get_sprite(background_element_id);
-Argument | -Type | -Description | -
---|---|---|
background_element_id | -Background Element ID | -The unique ID value of the background element to get the information from | -
-
Sprite Asset or -1
--
var lay_id = layer_get_id("Background_sky");
-
- var back_id = layer_background_get_id(lay_id);
-
- if (layer_background_get_sprite(back_id) != spr_Clouds)
-
- {
-
- layer_background_sprite(back_id, spr_Clouds);
-
- }
The above code will get the layer handle for the layer named "Background_sky" and then use that to get the ID of the background element on that layer. This ID is then used to check the sprite assigned to the element, setting it to the sprite "spr_Clouds" if it is not already.
--
-
-
This function can be used to get the current sprite of the background element. You give the background element ID (which you get when you create a background element using layer_background_create() or when you use the function layer_background_get_id()), and the function will return a handle that represents the sprite index being shown. If the element has no sprite assigned, the function will return -1.
++
layer_background_get_sprite(background_element_id);
+Argument | +Type | +Description | +
---|---|---|
background_element_id | +Background Element ID | +The unique ID value of the background element to get the information from | +
+
Sprite Asset or -1
++
var lay_id = layer_get_id("Background_sky");
+ var back_id = layer_background_get_id(lay_id);
+ if (layer_background_get_sprite(back_id) != spr_Clouds)
+ {
+ layer_background_sprite(back_id, spr_Clouds);
+ }
The above code will get the layer handle for the layer named "Background_sky" and then use that to get the ID of the background element on that layer. This ID is then used to check the sprite assigned to the element, setting it to the sprite "spr_Clouds" if it is not already.
++
+
+
This function can be used to get the stretched state of the background element sprite. You give the background element ID (which you get when you create a background element using layer_background_create() or when you use the function layer_background_get_id()), and the function will return either true if the element sprite is currently stretched to fit the room, or false if it is not.
--
layer_background_get_stretch(background_element_id);
-Argument | -Type | -Description | -
---|---|---|
background_element_id | -- | The unique ID value of the background element to get the information from | -
-
-
-
var lay_id = layer_get_id("Background_sky");
-
- var back_id = layer_background_get_id(lay_id);
-
- if (layer_background_get_stretch(back_id))
-
- {
-
- layer_background_stretch(back_id, false);
-
- }
The above code will get the layer handle for the layer named "Background_sky" and then use that to get the ID of the background element on that layer. This ID is then used to check and see if the element sprite will be stretched to fit the room or not and if it is stretched, then this property is set to false.
--
-
-
This function can be used to get the stretched state of the background element sprite. You give the background element ID (which you get when you create a background element using layer_background_create() or when you use the function layer_background_get_id()), and the function will return either true if the element sprite is currently stretched to fit the room, or false if it is not.
++
layer_background_get_stretch(background_element_id);
+Argument | +Type | +Description | +
---|---|---|
background_element_id | +Background Element ID | +The unique ID value of the background element to get the information from | +
+
+
var lay_id = layer_get_id("Background_sky");
+ var back_id = layer_background_get_id(lay_id);
+ if (layer_background_get_stretch(back_id))
+ {
+ layer_background_stretch(back_id, false);
+ }
The above code will get the layer handle for the layer named "Background_sky" and then use that to get the ID of the background element on that layer. This ID is then used to check and see if the element sprite will be stretched to fit the room or not and if it is stretched, then this property is set to false.
++
+
+
This function can be used to get the visible state of the background element. You give the background element ID (which you get when you create a background element using layer_background_create() or when you use the function layer_background_get_id()), and the function will return either true if the element is currently visible, or false if it is not. Note that this return value is not affected by whether the layer the element is on is visible or not.
--
layer_background_get_visible(background_element_id);
-Argument | -Type | -Description | -
---|---|---|
background_element_id | -- | The unique ID value of the background element to get the information from | -
-
-
-
var lay_id = layer_get_id("Background_sky");
-
- var back_id = layer_background_get_id(lay_id);
-
- if (layer_background_get_visible(back_id))
-
- {
-
- layer_background_visible(back_id, false);
-
- }
The above code will get the layer handle for the layer named "Background_sky" and then use that to get the ID of the background element on that layer. This ID is then used to check the element visibility and if it is visible, then this property is set to false.
--
-
-
This function can be used to get the visible state of the background element. You give the background element ID (which you get when you create a background element using layer_background_create() or when you use the function layer_background_get_id()), and the function will return either true if the element is currently visible, or false if it is not. Note that this return value is not affected by whether the layer the element is on is visible or not.
++
layer_background_get_visible(background_element_id);
+Argument | +Type | +Description | +
---|---|---|
background_element_id | +Background Element ID | +The unique ID value of the background element to get the information from | +
+
+
var lay_id = layer_get_id("Background_sky");
+ var back_id = layer_background_get_id(lay_id);
+ if (layer_background_get_visible(back_id))
+ {
+ layer_background_visible(back_id, false);
+ }
The above code will get the layer handle for the layer named "Background_sky" and then use that to get the ID of the background element on that layer. This ID is then used to check the element visibility and if it is visible, then this property is set to false.
++
+
+
This function can be used to find out if the background element is tiled vertically or not. You give the background element ID (which you get when you create a background element using layer_background_create() or when you use the function layer_background_get_id()), and the function will return either true if the element is currently tiled, or false if it is not.
--
layer_background_get_vtiled(background_element_id);
-Argument | -Type | -Description | -
---|---|---|
background_element_id | -- | The unique ID value of the background element to get the information from | -
-
-
-
var lay_id = layer_get_id("Background_sky");
-
- var back_id = layer_background_get_id(lay_id);
-
- if (!layer_background_get_vtiled(back_id))
-
- {
-
- layer_background_vtiled(back_id, true);
-
- }
The above code will get the layer handle for the layer named "Background_sky" and then use that to get the ID of the background element on that layer. This ID is then used to check if the element is tiling across the vertical axis, and if it is not then it is set to do so.
--
-
-
This function can be used to find out if the background element is tiled vertically or not. You give the background element ID (which you get when you create a background element using layer_background_create() or when you use the function layer_background_get_id()), and the function will return either true if the element is currently tiled, or false if it is not.
++
layer_background_get_vtiled(background_element_id);
+Argument | +Type | +Description | +
---|---|---|
background_element_id | +Background Element ID | +The unique ID value of the background element to get the information from | +
+
+
var lay_id = layer_get_id("Background_sky");
+ var back_id = layer_background_get_id(lay_id);
+ if (!layer_background_get_vtiled(back_id))
+ {
+ layer_background_vtiled(back_id, true);
+ }
The above code will get the layer handle for the layer named "Background_sky" and then use that to get the ID of the background element on that layer. This ID is then used to check if the element is tiling across the vertical axis, and if it is not then it is set to do so.
++
+
+
This function can be used to get the current scale multiplier value of the background element. You give the background element ID (which you get when you create a background element using layer_background_create() or when you use the function layer_background_get_id()), and the function will return real value that represents the scale multiplier being used to draw the sprite. Default value is 1.
--
layer_background_get_xscale(background_element_id);
-Argument | -Type | -Description | -
---|---|---|
background_element_id | -- | The unique ID value of the background element to get the information from | -
-
-
-
var lay_id = layer_get_id("Background_sky");
-
- var back_id = layer_background_get_id(lay_id);
-
- if (layer_background_get_xscale(back_id) != -1)
-
- {
-
- layer_background_xscale(back_id, -1);
-
- }
The above code will get the layer handle for the layer named "Background_sky" and then use that to get the ID of the background element on that layer. This ID is then used to check the x scale for the element and if it is not -1, it is set to -1.
--
-
-
This function can be used to get the current scale multiplier value of the background element. You give the background element ID (which you get when you create a background element using layer_background_create() or when you use the function layer_background_get_id()), and the function will return real value that represents the scale multiplier being used to draw the sprite. Default value is 1.
++
layer_background_get_xscale(background_element_id);
+Argument | +Type | +Description | +
---|---|---|
background_element_id | +Background Element ID | +The unique ID value of the background element to get the information from | +
+
+
var lay_id = layer_get_id("Background_sky");
+ var back_id = layer_background_get_id(lay_id);
+ if (layer_background_get_xscale(back_id) != -1)
+ {
+ layer_background_xscale(back_id, -1);
+ }
The above code will get the layer handle for the layer named "Background_sky" and then use that to get the ID of the background element on that layer. This ID is then used to check the x scale for the element and if it is not -1, it is set to -1.
++
+
+
This function can be used to get the current scale multiplier value of the background element. You give the background element ID (which you get when you create a background element using layer_background_create() or when you use the function layer_background_get_id()), and the function will return real value that represents the scale multiplier being used to draw the sprite. Default value is 1.
--
layer_background_get_yscale(background_element_id);
-Argument | -Type | -Description | -
---|---|---|
background_element_id | -- | The unique ID value of the background element to get the information from | -
-
-
-
var lay_id = layer_get_id("Background_sky");
-
- var back_id = layer_background_get_id(lay_id);
-
- if (layer_background_get_yscale(back_id) != -1)
-
- {
-
- layer_background_yscale(back_id, -1);
-
- }
The above code will get the layer handle for the layer named "Background_sky" and then use that to get the ID of the background element on that layer. This ID is then used to check the y scale for the element and if it is not -1, it is set to -1.
--
-
-
This function can be used to get the current scale multiplier value of the background element. You give the background element ID (which you get when you create a background element using layer_background_create() or when you use the function layer_background_get_id()), and the function will return real value that represents the scale multiplier being used to draw the sprite. Default value is 1.
++
layer_background_get_yscale(background_element_id);
+Argument | +Type | +Description | +
---|---|---|
background_element_id | +Background Element ID | +The unique ID value of the background element to get the information from | +
+
+
var lay_id = layer_get_id("Background_sky");
+ var back_id = layer_background_get_id(lay_id);
+ if (layer_background_get_yscale(back_id) != -1)
+ {
+ layer_background_yscale(back_id, -1);
+ }
The above code will get the layer handle for the layer named "Background_sky" and then use that to get the ID of the background element on that layer. This ID is then used to check the y scale for the element and if it is not -1, it is set to -1.
++
+
+
Using this function you can set the sprite index of the background element. You supply the background element ID (which you get when you create a background element using layer_background_create() or when you use the function layer_background_get_id()), and then give a sprite index to be used. The background element image will be replaced with the new sprite. If you give a value of -1, the element will have no sprite assigned (but will still exist and can have a sprite assigned again later).
-This function also has the alias layer_background_change().
--
layer_background_sprite(background_element_id, sprite_index)
-Argument | -Type | -Description | -
---|---|---|
background_element_id | -Background Element ID | -The unique ID value of the background element to change | -
sprite_index | -Sprite Asset | -The sprite index of the sprite to use for the background element | -
-
N/A
--
var lay_id = layer_get_id("Background_sky");
-
- var back_id = layer_background_get_id(lay_id);
-
- if (layer_background_get_sprite(back_id) != spr_Clouds)
-
- {
-
- layer_background_sprite(back_id, spr_Clouds);
-
- }
The above code will get the layer handle for the layer named "Background_sky" and then use that to get the ID of the background element on that layer. This ID is then used to check the sprite assigned to the element, setting it to the sprite "spr_Clouds" if it is not already.
--
-
-
Using this function you can set the sprite index of the background element. You supply the background element ID (which you get when you create a background element using layer_background_create() or when you use the function layer_background_get_id()), and then give a sprite index to be used. The background element image will be replaced with the new sprite. If you give a value of -1, the element will have no sprite assigned (but will still exist and can have a sprite assigned again later).
+This function also has the alias layer_background_change().
++
layer_background_sprite(background_element_id, sprite_index)
+Argument | +Type | +Description | +
---|---|---|
background_element_id | +Background Element ID | +The unique ID value of the background element to change | +
sprite_index | +Sprite Asset | +The sprite index of the sprite to use for the background element | +
+
N/A
++
var lay_id = layer_get_id("Background_sky");
+ var back_id = layer_background_get_id(lay_id);
+ if (layer_background_get_sprite(back_id) != spr_Clouds)
+ {
+ layer_background_sprite(back_id, spr_Clouds);
+ }
The above code will get the layer handle for the layer named "Background_sky" and then use that to get the ID of the background element on that layer. This ID is then used to check the sprite assigned to the element, setting it to the sprite "spr_Clouds" if it is not already.
++
+
+
This function is used to clear the FX struct that is applied to the specified layer. You specify either the ID or the name of the layer you want to modify and this function will remove the FX struct that is applied to that layer, disabling its effects completely.
-If you use this function to temporarily disable an effect and need to restore it layer, you should first save the FX struct for the layer by calling layer_get_fx() and then call this function to clear it on the layer. You can later apply it back to the layer by calling layer_set_fx(), which will re-enable the effect.
--
layer_clear_fx(layer_name_or_id);
-Argument | -Type | -Description | -
---|---|---|
layer_name_or_id | -String or Layer ID | -The name or ID of the layer to clear the FX for | -
-
N/A
--
// Disable effect
-
- if (keyboard_check_pressed(ord("E")))
-
- {
-
- if (layer_get_fx("EffectLayer") != -1)
-
- {
-
- temp_fx = layer_get_fx("EffectLayer");
-
- layer_clear_fx("EffectLayer");
-
- }
-
- }
-
- // Re-enable effect
-
- else if (keyboard_check_pressed(ord("F")))
-
- {
-
- if (temp_fx != -1)
-
- {
-
- layer_set_fx("EffectLayer", temp_fx);
-
- temp_fx = -1;
-
- }
-
- }
The above code checks if the "E" key is pressed, and then checks if the layer "EffectLayer" has a filter/effect applied to it; in that case it stores its FX struct in a temporary instance variable and clears the layer of any filters/effects. When the "F" key is pressed, it checks if the temporary variable holds something other than -1, and in that case it applies that FX back to the layer and resets the temporary variable to -1. All of this essentially allows you to enable and disable an effect whenever you need without losing its parameters.
--
-
-
This function is used to clear the FX struct that is applied to the specified layer. You specify either the ID or the name of the layer you want to modify and this function will remove the FX struct that is applied to that layer, disabling its effects completely.
+If you use this function to temporarily disable an effect and need to restore it layer, you should first save the FX struct for the layer by calling layer_get_fx() and then call this function to clear it on the layer. You can later apply it back to the layer by calling layer_set_fx(), which will re-enable the effect.
++
layer_clear_fx(layer_name_or_id);
+Argument | +Type | +Description | +
---|---|---|
layer_name_or_id | +String or Layer | +The name or ID of the layer to clear the FX for | +
+
N/A
++
// Disable effect
+ if (keyboard_check_pressed(ord("E")))
+ {
+ if (layer_get_fx("EffectLayer") != -1)
+ {
+ temp_fx = layer_get_fx("EffectLayer");
+ layer_clear_fx("EffectLayer");
+ }
+ }
+ // Re-enable effect
+ else if (keyboard_check_pressed(ord("F")))
+ {
+ if (temp_fx != -1)
+ {
+ layer_set_fx("EffectLayer", temp_fx);
+ temp_fx = -1;
+ }
+ }
The above code checks if the "E" key is pressed, and then checks if the layer "EffectLayer" has a filter/effect applied to it; in that case it stores its FX struct in a temporary instance variable and clears the layer of any filters/effects. When the "F" key is pressed, it checks if the temporary variable holds something other than -1, and in that case it applies that FX back to the layer and resets the temporary variable to -1. All of this essentially allows you to enable and disable an effect whenever you need without losing its parameters.
++
+
+
This function enables/disables the filter/effect assigned to a Room Layer. You specify either the ID or the name of the layer you want to modify, and then a boolean value telling whether the FX should be enabled (true) or disabled (false).
-Passing in false will not remove the FX from the layer, but simply make it invisible. Use layer_clear_fx() to remove an FX from a layer.
-Similarly, passing in true will not do anything if there is no FX applied to the layer. Use layer_set_fx() to apply an FX to a layer.
--
layer_enable_fx(layer_name_or_id, enable);
-Argument | -Type | -Description | -
---|---|---|
layer_name_or_id | -String or Layer ID | -The name or ID of the layer to modify | -
enable | -Boolean | -Whether to enable or disable the FX | -
-
N/A
--
if (hp <= 3)
-
- {
-
- layer_enable_fx("DesaturateLayer", true);
-
- }
-
- else
-
- {
-
- layer_enable_fx("DesaturateLayer", false);
-
- }
The above code enables a Desaturate FX layer if the instance's HP value is less than or equal to 3, otherwise it disables it. This indicates to the player that their HP is low, by desaturating the screen.
--
-
-
This function enables/disables the filter/effect assigned to a Room Layer. You specify either the ID or the name of the layer you want to modify, and then a boolean value telling whether the FX should be enabled (true) or disabled (false).
+Passing in false will not remove the FX from the layer, but simply make it invisible. Use layer_clear_fx() to remove an FX from a layer.
+Similarly, passing in true will not do anything if there is no FX applied to the layer. Use layer_set_fx() to apply an FX to a layer.
++
layer_enable_fx(layer_name_or_id, enable);
+Argument | +Type | +Description | +
---|---|---|
layer_name_or_id | +String or Layer | +The name or ID of the layer to modify | +
enable | +Boolean | +Whether to enable or disable the FX | +
+
N/A
++
if (hp <= 3)
+ {
+ layer_enable_fx("DesaturateLayer", true);
+ }
+ else
+ {
+ layer_enable_fx("DesaturateLayer", false);
+ }
The above code enables a Desaturate FX layer if the instance's HP value is less than or equal to 3, otherwise it disables it. This indicates to the player that their HP is low, by desaturating the screen.
++
+
+
This function returns whether the filter/effect for a layer is enabled.
-You specify either the ID or the name of the layer you want to target, and the function returns a boolean value indicating whether the layer's FX is enabled (true) or disabled (false).
--
layer_fx_is_enabled(layer_name_or_id);
-Argument | -Type | -Description | -
---|---|---|
layer_name_or_id | -String or Layer ID | -The name or ID of the layer to check | -
-
-
x = xstart;
-
- y = ystart;
-
- hp = hp_max;
-
-
- if (layer_fx_is_enabled("DesaturateLayer"))
-
- {
-
- layer_enable_fx("DesaturateLayer", false);
-
- }
The above code "respawns" the instance, by moving it to its original position and refilling its HP. It then checks if the Desaturate FX layer is enabled, and if it is, disables it.
--
-
-
This function returns whether the filter/effect for a layer is enabled.
+You specify either the ID or the name of the layer you want to target, and the function returns a boolean value indicating whether the layer's FX is enabled (true) or disabled (false).
++
layer_fx_is_enabled(layer_name_or_id);
+Argument | +Type | +Description | +
---|---|---|
layer_name_or_id | +String or Layer | +The name or ID of the layer to check | +
+
+
x = xstart;
+ y = ystart;
+ hp = hp_max;
+
+ if (layer_fx_is_enabled("DesaturateLayer"))
+ {
+ layer_enable_fx("DesaturateLayer", false);
+ }
+
The above code "respawns" the instance, by moving it to its original position and refilling its HP. It then checks if the Desaturate FX layer is enabled, and if it is, disables it.
++
+
+
This function is used to retrieve the FX struct for a layer. You specify either the ID or the name of the layer you want to target and the function will return a struct containing information on its applied effect. This struct will be similar to the struct you get from fx_create(), and the functions fx_get_parameter/s and fx_set_parameter/s can be used on it to read and modify its parameters.
-If the specified layer has no filters/effects applied to it, the function will return -1.
--
layer_get_fx(layer_name_or_id);
-Argument | -Type | -Description | -
---|---|---|
layer_name_or_id | -String or Layer ID | -The name or ID of the layer to read | -
-
FX Struct (or -1 if not found)
--
var layers = layer_get_all();
-
- for(var i = 0; i < array_length(layers); i ++)
-
- {
-
- var layer_fx = layer_get_fx(layers[i]);
-
-
- if (layer_fx != -1)
-
- {
-
- if (fx_get_name(layer_fx) == "_filter_tintfilter")
-
- {
-
- fx_set_parameter(layer_fx, "g_TintCol", [0, 0, 1, 1]);
-
- }
-
- }
-
- }
The above code runs a for loop through all the layers present in the room, and checks each layer for an FX struct. If a layer has an FX struct, it checks the name of that filter/effect by calling fx_get_name() on it; if it's equal to "_filter_tintfilter" meaning that it's a "Colour Tint" filter, it changes its tint colour to blue.
--
-
-
This function is used to retrieve the FX struct for a layer. You specify either the ID or the name of the layer you want to target and the function will return a struct containing information on its applied effect. This struct will be similar to the struct you get from fx_create(), and the functions fx_get_parameter/s and fx_set_parameter/s can be used on it to read and modify its parameters.
+If the specified layer has no filters/effects applied to it, the function will return -1.
++
layer_get_fx(layer_name_or_id);
+Argument | +Type | +Description | +
---|---|---|
layer_name_or_id | +String or Layer | +The name or ID of the layer to read | +
+
FX Struct (or -1 if not found)
++
var layers = layer_get_all();
+ for(var i = 0; i < array_length(layers); i ++)
+ {
+ var layer_fx = layer_get_fx(layers[i]);
+
+ if (layer_fx != -1)
+ {
+ if (fx_get_name(layer_fx) == "_filter_tintfilter")
+ {
+ fx_set_parameter(layer_fx, "g_TintCol", [0, 0, 1, 1]);
+ }
+ }
+ }
The above code runs a for loop through all the layers present in the room, and checks each layer for an FX struct. If a layer has an FX struct, it checks the name of that filter/effect by calling fx_get_name() on it; if it's equal to "_filter_tintfilter" meaning that it's a "Colour Tint" filter, it changes its tint colour to blue.
++
+
+
You can use this function to move an element from one layer to another. You give the element ID, as returned by the function used to create the element or the room editor or the function layer_get_all_elements(), and then you give the layer handle (which you get when you create the layer using layer_create()) or the layer name (as a string - this will have a performance impact).
--
layer_element_move(element_id, layer_id);
-Argument | -Type | -Description | -
---|---|---|
element_id | -Layer Element ID | -The unique ID value of the element to move | -
layer_id | -String or Layer | -The handle of the layer to move the element to (or the layer name as a string) | -
-
N/A
--
var a = layer_get_all_elements(layer);
-
- asset_layer = layer_create(-100);
-
- for (var i = 0; i < array_length(a); i++)
-
- {
-
- if layer_get_element_type(a[i]) == layerelementtype_sprite
-
- {
-
- layer_element_move(a[i], asset_layer)
-
- }
-
- }
The above code gets the elements on the layer that the instance running the code is assigned to, then checks them to see if they are sprite assets, and if they are then they are moved to the layer with the ID stored in the variable "asset_layer".
--
-
-
You can use this function to move an element from one layer to another. You give the element ID, as returned by the function used to create the element or the room editor or the function layer_get_all_elements(), and then you give the layer handle (which you get when you create the layer using layer_create()) or the layer name (as a string - this will have a performance impact).
++
layer_element_move(element_id, layer_id);
+Argument | +Type | +Description | +
---|---|---|
element_id | +Layer Element ID | +The unique ID value of the element to move | +
layer_id | +String or Layer | +The handle of the layer to move the element to (or the layer name as a string) | +
+
N/A
++
var a = layer_get_all_elements(layer);
+ asset_layer = layer_create(-100);
+ for (var i = 0; i < array_length(a); i++)
+ {
+ if layer_get_element_type(a[i]) == layerelementtype_sprite
+ {
+ layer_element_move(a[i], asset_layer)
+ }
+ }
The above code gets the elements on the layer that the instance running the code is assigned to, then checks them to see if they are sprite assets, and if they are then they are moved to the layer with the ID stored in the variable "asset_layer".
++
+
+
var lay_id = layer_get_id("Sprites");
- if layer_get_hspeed(lay_id) != 0 || layer_get_vspeed(lay_id) != 0
+ if (layer_get_hspeed(lay_id) != 0 || layer_get_vspeed(lay_id) != 0)
{
- layer_hspeed(lay_id, 0);
- layer_vspeed(lay_id, 0);
+ layer_hspeed(lay_id, 0);
+ layer_vspeed(lay_id, 0);
}
The above code checks the given layer horizontal and vertical speeds and if they are not both set to 0 then it is sets them to 0.
diff --git a/Manual/contents/GameMaker_Language/GML_Reference/Asset_Management/Rooms/General_Layer_Functions/layer_get_id_at_depth.htm b/Manual/contents/GameMaker_Language/GML_Reference/Asset_Management/Rooms/General_Layer_Functions/layer_get_id_at_depth.htm index cadbb81a9..017f961e8 100644 --- a/Manual/contents/GameMaker_Language/GML_Reference/Asset_Management/Rooms/General_Layer_Functions/layer_get_id_at_depth.htm +++ b/Manual/contents/GameMaker_Language/GML_Reference/Asset_Management/Rooms/General_Layer_Functions/layer_get_id_at_depth.htm @@ -40,7 +40,7 @@
var a = layer_get_id_at_depth(0);
- if a[0] != -1
+ if (a[0] != -1)
{
for (var i = 0; i < array_length(a); i++;)
{
diff --git a/Manual/contents/GameMaker_Language/GML_Reference/Asset_Management/Rooms/General_Layer_Functions/layer_get_name.htm b/Manual/contents/GameMaker_Language/GML_Reference/Asset_Management/Rooms/General_Layer_Functions/layer_get_name.htm
index 8a456dbbd..74b67fc11 100644
--- a/Manual/contents/GameMaker_Language/GML_Reference/Asset_Management/Rooms/General_Layer_Functions/layer_get_name.htm
+++ b/Manual/contents/GameMaker_Language/GML_Reference/Asset_Management/Rooms/General_Layer_Functions/layer_get_name.htm
@@ -1,76 +1,71 @@
-
+
-
This function gets the name of the given layer.
-You supply the unique layer handle value and if the layer is one of the named layers created in The Room Editor, then the function will return a string with the layer name. If the layer is not one of the Room Editor ones (i.e.: it was created using layer_create) then an empty string "" will be returned.
--
layer_get_name(layer_id)
-Argument | -Type | -Description | -
---|---|---|
layer_id | -Layer | -The handle of the layer to get the name of | -
-
-
var _arr_layers = layer_get_all();
-
- var _arr_layers_named = [];
-
- for (var i = 0; i < array_length(_arr_layers); i++)
-
- {
-
- if (layer_get_name(_arr_layers[i]) != "")
-
- {
-
- array_push(_arr_layers_named, _arr_layers[i]);
-
- }
-
- }
The above code gets the IDs of all the layers in the room and then loops through them to see if they're named layers. If they are they are then their ID is added to a list.
--
-
This function gets the name of the given layer.
+You supply the unique layer handle value and if the layer is one of the named layers created in The Room Editor, then the function will return a string with the layer name. If the layer is not one of the Room Editor ones (i.e.: it was created using layer_create) then an empty string "" will be returned.
++
layer_get_name(layer_id)
+Argument | +Type | +Description | +
---|---|---|
layer_id | +Layer | +The handle of the layer to get the name of | +
+
+
var _arr_layers = layer_get_all();
+ var _arr_layers_named = [];
+ for (var i = 0; i < array_length(_arr_layers); i++)
+ {
+ if (layer_get_name(_arr_layers[i]) != "")
+ {
+ array_push(_arr_layers_named, _arr_layers[i]);
+ }
+ }
The above code gets the IDs of all the layers in the room and then loops through them to see if they're named layers. If they are they are then their ID is added to a list.
++
+
You supply the layer handle (which you get when you create the layer using layer_create()) or the layer name (as a string - this will have a performance impact) and this function will return the script function index of the function assigned to run at the beginning of rendering for that layer, or it will return -1 if no function is assigned. You can assign script functions to a layer with layer_script_begin() and layer_script_end().
--
layer_get_script_begin(layer_id);
-Argument | -Type | -Description | -
---|---|---|
layer_id | -String or Layer ID | -The handle of the layer to target (or the layer name as a string) | -
-
Script Function or -1 (if no function is assigned)
--
if (layer_get_script_begin(layer) == -1)
-
- {
-
- layer_script_begin(layer, scr_SetShaderValues);
-
- }
The above code will check to see if the layer that the instance running the code has a script function assigned to it and if it doesn't one is assigned.
--
-
-
You supply the layer handle (which you get when you create the layer using layer_create()) or the layer name (as a string - this will have a performance impact) and this function will return the script function index of the function assigned to run at the beginning of rendering for that layer, or it will return -1 if no function is assigned. You can assign script functions to a layer with layer_script_begin() and layer_script_end().
++
layer_get_script_begin(layer_id);
+Argument | +Type | +Description | +
---|---|---|
layer_id | +String or Layer | +The handle of the layer to target (or the layer name as a string) | +
+
Script Function or -1 (if no function is assigned)
++
if (layer_get_script_begin(layer) == -1)
+ {
+ layer_script_begin(layer, scr_SetShaderValues);
+ }
The above code will check to see if the layer that the instance running the code has a script function assigned to it and if it doesn't one is assigned.
++
+
+
This function returns the script function index of the function assigned to run at the end of rendering the given layer, or it will return -1 if no function is assigned. You supply the layer handle (which you get when you create the layer using layer_create()) or the layer name (as a string - this will have a performance impact). You can assign script functions to a layer with layer_script_begin() and layer_script_end().
--
layer_get_script_end(layer_id);
-Argument | -Type | -Description | -
---|---|---|
layer_id | -String or Layer ID | -The handle of the layer to target (or the layer name as a string) | -
-
Script Function or -1 (if no function is assigned)
--
if (layer_get_script_end(layer) == -1)
-
- {
-
- layer_script_end(layer, scr_ResetShaderValues);
-
- }
The above code will check to see if the layer that the instance running the code has a script function assigned to it and if it doesn't one is assigned.
--
-
-
This function returns the script function index of the function assigned to run at the end of rendering the given layer, or it will return -1 if no function is assigned. You supply the layer handle (which you get when you create the layer using layer_create()) or the layer name (as a string - this will have a performance impact). You can assign script functions to a layer with layer_script_begin() and layer_script_end().
++
layer_get_script_end(layer_id);
+Argument | +Type | +Description | +
---|---|---|
layer_id | +String or Layer | +The handle of the layer to target (or the layer name as a string) | +
+
Script Function or -1 (if no function is assigned)
++
if (layer_get_script_end(layer) == -1)
+ {
+ layer_script_end(layer, scr_ResetShaderValues);
+ }
The above code will check to see if the layer that the instance running the code has a script function assigned to it and if it doesn't one is assigned.
++
+
+
This function can be used to check if the given layer has a shader assigned to it. You supply the layer handle (which you get when you create the layer using layer_create()) or the layer name (as a string - this will have a performance impact), and the function will return either the shader index of the shader assigned, or -1 if no shader is assigned.
--
layer_get_shader(layer_id)
-Argument | -Type | -Description | -
---|---|---|
layer_id | -String or Layer ID | -The handle of the layer to target (or the layer name as a string) | -
-
Shader Asset or -1 (if no shader is assigned)
--
if (layer_get_shader(layer) == -1)
-
- {
-
- layer_shader(layer, shd_Sepia);
-
- }
The above code will check to see if the layer that the instance running the code has a shader assigned to it and if it doesn't one is assigned.
--
-
-
This function can be used to check if the given layer has a shader assigned to it. You supply the layer handle (which you get when you create the layer using layer_create()) or the layer name (as a string - this will have a performance impact), and the function will return either the shader index of the shader assigned, or -1 if no shader is assigned.
++
layer_get_shader(layer_id)
+Argument | +Type | +Description | +
---|---|---|
layer_id | +String or Layer | +The handle of the layer to target (or the layer name as a string) | +
+
Shader Asset or -1 (if no shader is assigned)
++
if (layer_get_shader(layer) == -1)
+ {
+ layer_shader(layer, shd_Sepia);
+ }
The above code will check to see if the layer that the instance running the code has a shader assigned to it and if it doesn't one is assigned.
++
+
+
var lay_id = layer_get_id("Instances");
if (layer_get_visible(lay_id))
{
- layer_set_visible(lay_id, false);
+ layer_set_visible(lay_id, false);
}
else
{
- layer_set_visible(lay_id, true);
+ layer_set_visible(lay_id, true);
}
The above code gets the handle for the layer named "Instances" in the room editor, then uses the ID to check if the layer is visible or not, toggling the layer visibility depending on the returned value.
diff --git a/Manual/contents/GameMaker_Language/GML_Reference/Asset_Management/Rooms/General_Layer_Functions/layer_get_vspeed.htm b/Manual/contents/GameMaker_Language/GML_Reference/Asset_Management/Rooms/General_Layer_Functions/layer_get_vspeed.htm index 78016ef20..f9494b4c1 100644 --- a/Manual/contents/GameMaker_Language/GML_Reference/Asset_Management/Rooms/General_Layer_Functions/layer_get_vspeed.htm +++ b/Manual/contents/GameMaker_Language/GML_Reference/Asset_Management/Rooms/General_Layer_Functions/layer_get_vspeed.htm @@ -1,70 +1,68 @@ - + - - -
You can use this function to retrieve the vertical speed (in pixels per game frame) of the layer within the currently scoped room. You supply the layer handle (which you get when you create the layer using layer_create()) or the layer name (as a string - this will have a performance impact) and the function returns a real number for the vertical speed, where a positive value is down and a negative value up. Default is 0 (unless set in the room editor).
--
layer_get_vspeed(layer_id)
-Argument | -Type | -Description | -
---|---|---|
layer_id | -String or Layer ID | -The handle of the layer to get the vertical speed from | -
-
N/A
--
var lay_id = layer_get_id("Sprites");
-
- if layer_get_hspeed(lay_id) != 0 || layer_get_vspeed(lay_id) != 0
-
- {
-
- layer_hspeed(lay_id, 0);
-
- layer_vspeed(lay_id, 0);
-
- }
The above code checks the given layer horizontal and vertical speeds and if they are not both set to 0 then it is sets them to 0.
--
-
-
You can use this function to retrieve the vertical speed (in pixels per game frame) of the layer within the currently scoped room. You supply the layer handle (which you get when you create the layer using layer_create()) or the layer name (as a string - this will have a performance impact) and the function returns a real number for the vertical speed, where a positive value is down and a negative value up. Default is 0 (unless set in the room editor).
++
layer_get_vspeed(layer_id)
+Argument | +Type | +Description | +
---|---|---|
layer_id | +String or Layer | +The handle of the layer to get the vertical speed from | +
+
N/A
++
var lay_id = layer_get_id("Sprites");
+ if (layer_get_hspeed(lay_id) != 0 || layer_get_vspeed(lay_id) != 0)
+ {
+ layer_hspeed(lay_id, 0);
+ layer_vspeed(lay_id, 0);
+ }
The above code checks the given layer horizontal and vertical speeds and if they are not both set to 0 then it is sets them to 0.
++
+
+
You can use this function to retrieve the x position of the layer within the currently scoped room. You supply the layer handle (which you get when you create the layer using layer_create()) or the layer name (as a string - this will have a performance impact) and the function returns a real number for the x position of the layer, relative to the (0,0) position of the room. Default is 0.
--
layer_get_x(layer_id)
-Argument | -Type | -Description | -
---|---|---|
layer_id | -String or Layer ID | -The handle of the layer to get the x position of | -
-
Real
--
var lay_id = layer_get_id("Sprites");
-
- if layer_get_x(lay_id) != 0 || layer_get_y(lay_id) != 0
-
- {
-
- layer_x(lay_id, 0);
-
- layer_y(lay_id, 0);
-
- }
The above code checks the given layer position and if it is not set to (0, 0) then it is set to that position.
--
-
-
You can use this function to retrieve the x position of the layer within the currently scoped room. You supply the layer handle (which you get when you create the layer using layer_create()) or the layer name (as a string - this will have a performance impact) and the function returns a real number for the x position of the layer, relative to the (0,0) position of the room. Default is 0.
++
layer_get_x(layer_id)
+Argument | +Type | +Description | +
---|---|---|
layer_id | +String or Layer | +The handle of the layer to get the x position of | +
+
+
var lay_id = layer_get_id("Sprites");
+ if (layer_get_x(lay_id) != 0 || layer_get_y(lay_id) != 0)
+ {
+ layer_x(lay_id, 0);
+ layer_y(lay_id, 0);
+ }
The above code checks the given layer position and if it is not set to (0, 0) then it is set to that position.
++
+
+
You can use this function to retrieve the y position of the layer within the currently scoped room. You supply the layer handle (which you get when you create the layer using layer_create()) or the layer name (as a string - this will have a performance impact) and the function returns a real number for the x position of the layer, relative to the (0,0) position of the room. Default is 0.
--
layer_get_y(layer_id)
-Argument | -Type | -Description | -
---|---|---|
layer_id | -String or Layer ID | -The handle of the layer to get the y position of | -
-
Real
--
var lay_id = layer_get_id("Sprites");
-
- if layer_get_x(lay_id) != 0 || layer_get_y(lay_id) != 0
-
- {
-
- layer_x(lay_id, 0);
-
- layer_y(lay_id, 0);
-
- }
The above code checks the given layer position and if it is not set to (0, 0) then it is set to that position.
--
-
-
You can use this function to retrieve the y position of the layer within the currently scoped room. You supply the layer handle (which you get when you create the layer using layer_create()) or the layer name (as a string - this will have a performance impact) and the function returns a real number for the x position of the layer, relative to the (0,0) position of the room. Default is 0.
++
layer_get_y(layer_id)
+Argument | +Type | +Description | +
---|---|---|
layer_id | +String or Layer | +The handle of the layer to get the y position of | +
+
+
var lay_id = layer_get_id("Sprites");
+ if (layer_get_x(lay_id) != 0 || layer_get_y(lay_id) != 0)
+ {
+ layer_x(lay_id, 0);
+ layer_y(lay_id, 0);
+ }
The above code checks the given layer position and if it is not set to (0, 0) then it is set to that position.
++
+
+
This function can be used to check if a given instance is currently assigned to the given layer. You supply the layer handle (which you get when you create the layer using layer_create()) or the layer name (as a string - this will have a performance impact) and the instance ID of the instance to check for. You can also give an object_index (ie: the name of the object in the Asset Browser) and the function will check if any instances of that object are on the given layer. The function will return true if the instance is on the layer and false if it is not.
--
layer_has_instance(layer_id, instance_id)
-Argument | -Type | -Description | -
---|---|---|
layer_id | -String or Layer ID | -The handle of the layer to target (or the layer name as a string) | -
instance_id | -Instance ID | -The unique instance ID or the object index of the instance to check for | -
-
Boolean
--
if (!layer_has_instance(global.Bullet_Layer, obj_Bullet_Parent))
-
- {
-
- layer_destroy(global.Bullet_Layer);
-
- }
The above code will check to see if the given layer contains any instances of the object "obj_Bullet_Parent" and if not it will destroy the layer.
--
-
-
This function can be used to check if a given instance is currently assigned to the given layer. You supply the layer handle (which you get when you create the layer using layer_create()) or the layer name (as a string - this will have a performance impact) and the instance ID of the instance to check for. You can also give an object_index (ie: the name of the object in the Asset Browser) and the function will check if any instances of that object are on the given layer. The function will return true if the instance is on the layer and false if it is not.
++
layer_has_instance(layer_id, instance_id)
+Argument | +Type | +Description | +
---|---|---|
layer_id | +String or Layer | +The handle of the layer to target (or the layer name as a string) | +
instance_id | +Object Instance | +The unique instance ID or the object index of the instance to check for | +
+
+
if (!layer_has_instance(global.Bullet_Layer, obj_Bullet_Parent))
+ {
+ layer_destroy(global.Bullet_Layer);
+ }
The above code will check to see if the given layer contains any instances of the object "obj_Bullet_Parent" and if not it will destroy the layer.
++
+
+
You can use this function to set the horizontal speed (in pixels per game frame) of the layer within the currently scoped room.
-You supply the layer handle (which you get when you create the layer using layer_create) or the layer name (as a string - this will have a performance impact) and the speed value to set, where a positive value is to the right and a negative value to the left.
--
layer_hspeed(layer_id, hspd)
-Argument | -Type | -Description | -
---|---|---|
layer_id | -String or Layer ID | -The handle of the layer to set the horizontal speed of | -
hspd | -Real | -The horizontal speed (in pixels per game frame) to set | -
-
N/A
--
var lay_id = layer_get_id("Sprites");
-
- if layer_get_hspeed(lay_id) != 0 || layer_get_vspeed(lay_id) != 0
-
- {
-
- layer_hspeed(lay_id, 0);
-
- layer_vspeed(lay_id, 0);
-
- }
The above code checks the given layer horizontal and vertical speeds and if they are not both set to 0 then it is sets them to 0.
--
-
You can use this function to set the horizontal speed (in pixels per game frame) of the layer within the currently scoped room.
+You supply the layer handle (which you get when you create the layer using layer_create) or the layer name (as a string - this will have a performance impact) and the speed value to set, where a positive value is to the right and a negative value to the left.
++
layer_hspeed(layer_id, hspd)
+Argument | +Type | +Description | +
---|---|---|
layer_id | +String or Layer | +The handle of the layer to set the horizontal speed of | +
hspd | +Real | +The horizontal speed (in pixels per game frame) to set | +
+
N/A
++
var lay_id = layer_get_id("Sprites");
+ if layer_get_hspeed(lay_id) != 0 || layer_get_vspeed(lay_id) != 0
+ {
+ layer_hspeed(lay_id, 0);
+ layer_vspeed(lay_id, 0);
+ }
The above code checks the given layer horizontal and vertical speeds and if they are not both set to 0 then it is sets them to 0.
++
+
This function is used to reset the layer target to the current room. See the function layer_set_target_room() for further information.
--
layer_reset_target_room()
--
-
-
layer_set_target_room(rm_Game);
-
- var l = layer_get_id("SpriteAssets");
-
- repeat(50)
-
- {
-
- layer_sprite_create(l, irandom(1000), irandom(1000), spr_Trees);
-
- }
-
- layer_reset_target_room();
The above code sets the target room to the room "rm_Game" and then gets the layer handle for the layer called "SpriteAssets" in that room. This layer handle is then used to add 50 random sprite assets to the layer, before the layer target is reset to the current room.
--
-
-
This function is used to reset the layer target to the current room. See the function layer_set_target_room() for further information.
++
layer_reset_target_room()
++
N/A
++
layer_set_target_room(rm_Game);
+ var l = layer_get_id("SpriteAssets");
+ repeat(50)
+ {
+ layer_sprite_create(l, irandom(1000), irandom(1000), spr_Trees);
+ }
+ layer_reset_target_room();
The above code sets the target room to the room "rm_Game" and then gets the layer handle for the layer called "SpriteAssets" in that room. This layer handle is then used to add 50 random sprite assets to the layer, before the layer target is reset to the current room.
++
+
+
With this function you can assign a script function to a layer and it will be called before the layer is rendered. When adding a function to a layer, in this way it will be run at the start of each of the different draw events so you may want to check in the function assigned which event is currently rendering and adapt the code to suit. This can be done by checking the event_type and/or the event_number (see the extended example below). Note that the function is not meant to be called in any draw events or step events, but rather only needs to be called at the start of the room in the Room Creation Code or in the Create Event / Room Start Event of an instance.
--
layer_script_begin(layer_id, script);
-Argument | -Type | -Description | -
---|---|---|
layer_id | -String or Layer ID | -The handle of the layer to target (or the layer name as a string) | -
script | -Script Function | -The script function index to assign to the layer | -
-
N/A
--
In this extended example, we will first show you how a simple script function is structured to set some shader uniform data so that when the given layer is drawn, this function will be run and the shader will work correctly. In the example, it is worth noting how we check which event is being called so that the rest of the function is only run on the specific event that we require it to work on - in this case, only on the main draw event:
-/// @function layer_shader_start();
-
- function layer_shader_start()
-
- {
-
- if (event_type == ev_draw)
-
- {
-
- if (event_number == ev_draw_normal)
-
- {
-
- colour_to_find = shader_get_uniform(sShaderDemo5, "f_Colour1");
-
- colour_to_set = shader_get_uniform(sShaderDemo5, "f_Colour2");
-
- shader_set(s_ColourChanger);
-
- shader_set_uniform_f(colour_to_find, 1, 1, 1);
-
- shader_set_uniform_f(colour_to_set, 1, 0, 0);
-
- }
-
- }
-
- }
We would then have a companion function to reset the shader after all the drawing is done:
-/// @function layer_shader_end();
-
- function layer_shader_end()
-
- {
-
- if (event_type == ev_draw)
-
- {
-
- if (event_number == ev_draw_normal)
-
- {
-
- shader_reset();
-
- }
-
- }
-
- }
Now that we have defined our script functions for setting the shader, we then have to assign them to a specific layer so that the layer knows to call them. This would be done in the room creation code, or in the create event or room start event of some controller object (they do not need to be set every step, but rather once at the start of the room, or when the layer is initially created):
-var lay_id = layer_get_id("Instances");
-
- layer_script_begin(lay_id, layer_shader_start);
-
- layer_script_end(lay_id, layer_shader_end);
This final code block assigns the scripts to the layer.
--
-
-
With this function you can assign a script function to a layer and it will be called before the layer is rendered. When adding a function to a layer, in this way it will be run at the start of each of the different draw events so you may want to check in the function assigned which event is currently rendering and adapt the code to suit. This can be done by checking the event_type and/or the event_number (see the extended example below). Note that the function is not meant to be called in any draw events or step events, but rather only needs to be called at the start of the room in the Room Creation Code or in the Create Event / Room Start Event of an instance.
++
layer_script_begin(layer_id, script);
+Argument | +Type | +Description | +
---|---|---|
layer_id | +String or Layer | +The handle of the layer to target (or the layer name as a string) | +
script | +Script Function | +The script function index to assign to the layer | +
+
N/A
++
In this extended example, we will first show you how a simple script function is structured to set some shader uniform data so that when the given layer is drawn, this function will be run and the shader will work correctly. In the example, it is worth noting how we check which event is being called so that the rest of the function is only run on the specific event that we require it to work on - in this case, only on the main draw event:
+/// @function layer_shader_start();
+ function layer_shader_start()
+ {
+ if (event_type == ev_draw)
+ {
+ if (event_number == ev_draw_normal)
+ {
+ colour_to_find = shader_get_uniform(sShaderDemo5, "f_Colour1");
+ colour_to_set = shader_get_uniform(sShaderDemo5, "f_Colour2");
+ shader_set(s_ColourChanger);
+ shader_set_uniform_f(colour_to_find, 1, 1, 1);
+ shader_set_uniform_f(colour_to_set, 1, 0, 0);
+ }
+ }
+ }
We would then have a companion function to reset the shader after all the drawing is done:
+/// @function layer_shader_end();
+ function layer_shader_end()
+ {
+ if (event_type == ev_draw)
+ {
+ if (event_number == ev_draw_normal)
+ {
+ shader_reset();
+ }
+ }
+ }
Now that we have defined our script functions for setting the shader, we then have to assign them to a specific layer so that the layer knows to call them. This would be done in the room creation code, or in the create event or room start event of some controller object (they do not need to be set every step, but rather once at the start of the room, or when the layer is initially created):
+var lay_id = layer_get_id("Instances");
+ layer_script_begin(lay_id, layer_shader_start);
+ layer_script_end(lay_id, layer_shader_end);
+
This final code block assigns the scripts to the layer.
++
+
+
With this function you can assign a script function to a layer and it will be called after the layer is rendered. When adding a function to a layer in this way, it will be run at the end of each of the different draw events so you may want to check in the function assigned which event is currently finished rendering and adapt the code to suit. This can be done by checking the event_type and/or the event_number (see the extended example below). Note that the function is not meant to be called in any draw events or step events, but rather only needs to be called at the start of the room in the Room Creation Code or in the Create Event / Room Start Event of an instance.
--
layer_script_end(layer_id, script);
-Argument | -Type | -Description | -
---|---|---|
layer_id | -String or Layer ID | -The handle of the layer to target (or the layer name as a string) | -
script | -Script Function | -The script function index to assign to the layer | -
-
N/A
--
In this extended example, we will first show you how a simple script function is structured to set some shader uniform data so that when the given layer is drawn, this function will be run and the shader will work correctly. In the example, it is worth noting how we check which event is being called so that the rest of the function is only run on the specific event that we require it to work on - in this case, only on the main draw event:
-/// @function layer_shader_start();
-
- function layer_shader_start()
-
- {
-
- if (event_type == ev_draw)
-
- {
-
- if (event_number == ev_draw_normal)
-
- {
-
- colour_to_find = shader_get_uniform(sShaderDemo5, "f_Colour1");
-
- colour_to_set = shader_get_uniform(sShaderDemo5, "f_Colour2");
-
- shader_set(s_ColourChanger);
-
- shader_set_uniform_f(colour_to_find, 1, 1, 1);
-
- shader_set_uniform_f(colour_to_set, 1, 0, 0);
-
- }
-
- }
-
- }
We would then have a companion function to reset the shader after all the drawing is done:
-/// @function layer_shader_end();
-
- function layer_shader_end()
-
- {
-
- if (event_type == ev_draw)
-
- {
-
- if (event_number == ev_draw_normal)
-
- {
-
- shader_reset();
-
- }
-
- }
-
- }
Now that we have defined our script functions for setting the shader, we then have to assign them to a specific layer so that the layer knows to call them. This would be done in the room creation code, or in the create event or room start event of some controller object (they do not need to be set every step, but rather once at the start of the room, or when the layer is initially created):
-var lay_id = layer_get_id("Instances");
-
- layer_script_begin(lay_id, layer_shader_start);
-
- layer_script_end(lay_id, layer_shader_end);
This final code block assigns the scripts to the layer.
--
-
-
With this function you can assign a script function to a layer and it will be called after the layer is rendered. When adding a function to a layer in this way, it will be run at the end of each of the different draw events so you may want to check in the function assigned which event is currently finished rendering and adapt the code to suit. This can be done by checking the event_type and/or the event_number (see the extended example below). Note that the function is not meant to be called in any draw events or step events, but rather only needs to be called at the start of the room in the Room Creation Code or in the Create Event / Room Start Event of an instance.
++
layer_script_end(layer_id, script);
+Argument | +Type | +Description | +
---|---|---|
layer_id | +String or Layer | +The handle of the layer to target (or the layer name as a string) | +
script | +Script Function | +The script function index to assign to the layer | +
+
N/A
++
In this extended example, we will first show you how a simple script function is structured to set some shader uniform data so that when the given layer is drawn, this function will be run and the shader will work correctly. In the example, it is worth noting how we check which event is being called so that the rest of the function is only run on the specific event that we require it to work on - in this case, only on the main draw event:
+/// @function layer_shader_start();
+ function layer_shader_start()
+ {
+ if (event_type == ev_draw)
+ {
+ if (event_number == ev_draw_normal)
+ {
+ colour_to_find = shader_get_uniform(sShaderDemo5, "f_Colour1");
+ colour_to_set = shader_get_uniform(sShaderDemo5, "f_Colour2");
+ shader_set(s_ColourChanger);
+ shader_set_uniform_f(colour_to_find, 1, 1, 1);
+ shader_set_uniform_f(colour_to_set, 1, 0, 0);
+ }
+ }
+ }
We would then have a companion function to reset the shader after all the drawing is done:
+/// @function layer_shader_end();
+ function layer_shader_end()
+ {
+ if (event_type == ev_draw)
+ {
+ if (event_number == ev_draw_normal)
+ {
+ shader_reset();
+ }
+ }
+ }
Now that we have defined our script functions for setting the shader, we then have to assign them to a specific layer so that the layer knows to call them. This would be done in the room creation code, or in the create event or room start event of some controller object (they do not need to be set every step, but rather once at the start of the room, or when the layer is initially created):
+var lay_id = layer_get_id("Instances");
+ layer_script_begin(lay_id, layer_shader_start);
+ layer_script_end(lay_id, layer_shader_end);
+
This final code block assigns the scripts to the layer.
++
+
+
This function tells GameMaker that all further layer functions should be applied to the given room. In this way you can procedurally change or generate layers and layer contents in a room that is not the current room.
-When you are finished adding layers or layer elements to a room, call the function layer_reset_target_room to reset the room target or call this function again with a room argument of -1.
-While targeting another room, you can use all the regular layer functions except you cannot create instances using instance_create_layer or instance_create_depth, nor will the layer function layer_add_instance be available.
--
layer_set_target_room(room);
-Argument | -Type | -Description | -
---|---|---|
room | -Room Asset | -The room to target for all further layer functions, or -1 for the current room | -
-
N/A
--
layer_set_target_room(rm_Game);
-
- var l = layer_get_id("SpriteAssets");
-
- repeat(50)
-
- {
-
- var _x = irandom(1000);
-
- var _y = irandom(1000);
-
- layer_sprite_create(l, _x, _y, spr_Trees);
-
- }
-
- layer_reset_target_room();
The above code sets the target room to the room "rm_Game" and then gets the layer handle for the layer called "SpriteAssets" in that room. This layer handle is then used to add 50 random sprite assets to the layer, before the layer target is reset to the current room.
--
-
This function tells GameMaker that all further layer functions should be applied to the given room. In this way you can procedurally change or generate layers and layer contents in a room that is not the current room.
+When you are finished adding layers or layer elements to a room, call the function layer_reset_target_room to reset the room target or call this function again with a room argument of -1.
+While targeting another room, you can use all the regular layer functions except you cannot create instances using instance_create_layer or instance_create_depth, nor will the layer function layer_add_instance be available.
++
layer_set_target_room(room);
+Argument | +Type | +Description | +
---|---|---|
room | +Room Asset | +The room to target for all further layer functions, or -1 for the current room | +
+
N/A
++
layer_set_target_room(rm_Game);
+ var l = layer_get_id("SpriteAssets");
+ repeat(50)
+ {
+ var _x = irandom(1000);
+ var _y = irandom(1000);
+ layer_sprite_create(l, _x, _y, spr_Trees);
+ }
+ layer_reset_target_room();
The above code sets the target room to the room "rm_Game" and then gets the layer handle for the layer called "SpriteAssets" in that room. This layer handle is then used to add 50 random sprite assets to the layer, before the layer target is reset to the current room.
++
+
var lay_id = layer_get_id("Instances");
if (layer_get_visible(lay_id))
{
- layer_set_visible(lay_id, false);
+ layer_set_visible(lay_id, false);
}
else
{
- layer_set_visible(lay_id, true);
+ layer_set_visible(lay_id, true);
}
The above code gets the handle for the layer named "Instances" in the room editor, then uses the ID to check if the layer is visible or not, toggling the layer visibility depending on the returned value.
diff --git a/Manual/contents/GameMaker_Language/GML_Reference/Asset_Management/Rooms/General_Layer_Functions/layer_vspeed.htm b/Manual/contents/GameMaker_Language/GML_Reference/Asset_Management/Rooms/General_Layer_Functions/layer_vspeed.htm index 0c537f55d..fe19709f2 100644 --- a/Manual/contents/GameMaker_Language/GML_Reference/Asset_Management/Rooms/General_Layer_Functions/layer_vspeed.htm +++ b/Manual/contents/GameMaker_Language/GML_Reference/Asset_Management/Rooms/General_Layer_Functions/layer_vspeed.htm @@ -1,75 +1,73 @@ - + - - -
You can use this function to set the vertical speed (in pixels per game frame) of the layer within the currently scoped room.
-You supply the layer handle (which you get when you create the layer using layer_create) or the layer name (as a string - this will have a performance impact) and the speed value to set, where a positive value is downwards and a negative value upwards.
--
layer_vspeed(layer_id, vspd)
-Argument | -Type | -Description | -
---|---|---|
layer_id | -String or Layer ID | -The handle of the layer to set the vertical speed of | -
vspd | -Real | -The vertical speed (in pixels per game frame) to set | -
-
N/A
--
var lay_id = layer_get_id("Sprites");
-
- if layer_get_hspeed(lay_id) != 0 || layer_get_vspeed(lay_id) != 0
-
- {
-
- layer_hspeed(lay_id, 0);
-
- layer_vspeed(lay_id, 0);
-
- }
The above code checks the given layer horizontal and vertical speeds and if they are not both set to 0 then it is sets them to 0.
--
-
You can use this function to set the vertical speed (in pixels per game frame) of the layer within the currently scoped room.
+You supply the layer handle (which you get when you create the layer using layer_create) or the layer name (as a string - this will have a performance impact) and the speed value to set, where a positive value is downwards and a negative value upwards.
++
layer_vspeed(layer_id, vspd)
+Argument | +Type | +Description | +
---|---|---|
layer_id | +String or Layer | +The handle of the layer to set the vertical speed of | +
vspd | +Real | +The vertical speed (in pixels per game frame) to set | +
+
N/A
++
var lay_id = layer_get_id("Sprites");
+ if (layer_get_hspeed(lay_id) != 0 || layer_get_vspeed(lay_id) != 0)
+ {
+ layer_hspeed(lay_id, 0);
+ layer_vspeed(lay_id, 0);
+ }
The above code checks the given layer horizontal and vertical speeds and if they are not both set to 0 then it is sets them to 0.
++
+
You can use this function to set the x position of the layer within the currently scoped room.
-You supply the layer handle (which you get when you create the layer using layer_create) or the layer name (as a string - this will have a performance impact) and the function will move the layer the given number of pixels along the horizontal axis of the room.
--
layer_x(layer_id, x)
-Argument | -Type | -Description | -
---|---|---|
layer_id | -String or Layer ID | -The handle of the layer to set the x position of | -
x | -Real | -The x position in the room to set the layer to | -
-
N/A
--
var lay_id = layer_get_id("Sprites");
-
- if layer_get_x(lay_id) != 0 || layer_get_y(lay_id) != 0
-
- {
-
- layer_x(lay_id, 0);
-
- layer_y(lay_id, 0);
-
- }
The above code checks the given layer position and if it is not set to (0, 0) then it is set to that position.
--
-
You can use this function to set the x position of the layer within the currently scoped room.
+You supply the layer handle (which you get when you create the layer using layer_create) or the layer name (as a string - this will have a performance impact) and the function will move the layer the given number of pixels along the horizontal axis of the room.
++
layer_x(layer_id, x)
+Argument | +Type | +Description | +
---|---|---|
layer_id | +String or Layer | +The handle of the layer to set the x position of | +
x | +Real | +The x position in the room to set the layer to | +
+
N/A
++
var lay_id = layer_get_id("Sprites");
+ if layer_get_x(lay_id) != 0 || layer_get_y(lay_id) != 0
+ {
+ layer_x(lay_id, 0);
+ layer_y(lay_id, 0);
+ }
The above code checks the given layer position and if it is not set to (0, 0) then it is set to that position.
++
+
You can use this function to set the y position of the layer within the currently scoped room.
-You supply the layer handle (which you get when you create the layer using layer_create) or the layer name (as a string - this will have a performance impact) and the function will move the layer the given number of pixels along the vertical axis of the room.
--
layer_y(layer_id, y)
-Argument | -Type | -Description | -
---|---|---|
layer_id | -String or Layer ID | -The handle of the layer to set the y position of | -
y | -Real | -The y position in the room to set the layer to | -
-
N/A
--
var lay_id = layer_get_id("Sprites");
-
- if layer_get_x(lay_id) != 0 || layer_get_y(lay_id) != 0
-
- {
-
- layer_x(lay_id, 0);
-
- layer_y(lay_id, 0);
-
- }
The above code checks the given layer position and if it is not set to (0, 0) then it is set to that position.
--
-
You can use this function to set the y position of the layer within the currently scoped room.
+You supply the layer handle (which you get when you create the layer using layer_create) or the layer name (as a string - this will have a performance impact) and the function will move the layer the given number of pixels along the vertical axis of the room.
++
layer_y(layer_id, y)
+Argument | +Type | +Description | +
---|---|---|
layer_id | +String or Layer | +The handle of the layer to set the y position of | +
y | +Real | +The y position in the room to set the layer to | +
+
N/A
++
var lay_id = layer_get_id("Sprites");
+ if layer_get_x(lay_id) != 0 || layer_get_y(lay_id) != 0
+ {
+ layer_x(lay_id, 0);
+ layer_y(lay_id, 0);
+ }
The above code checks the given layer position and if it is not set to (0, 0) then it is set to that position.
++
+
With this function you can check to see if a sequence element exists on the given layer. You supply the layer handle which can be a string of the layer name - as defined in the Room Editor - or the unique layer handle - as returned by the function layer_get_id(), as well the sequence element ID - as returned by layer_sequence_create() or by one of the layer element functions - and it will return true if the given element exists or false otherwise.
--
layer_sequence_exists(layer_id, sequence_element_id)
-Argument | -Type | -Description | -
---|---|---|
layer_ID | -String or Layer ID | -The unique ID or name of the layer to check | -
sequence_element_id | -Sequence Element ID | -The unique ID value of the sequence element to target | -
-
-
if (!layer_sequence_exists("Background", my_seq))
-
- {
-
- my_seq = layer_sequence_create("Background", 0, 0, seq_AnimatedBackground);
-
- layer_sequence_pause(my_seq);
-
- }
The above code checks to see if the given sequence element exists, and if it does not then it creates a new sequence on the given layer then pauses it.
--
-
-
With this function you can check to see if a sequence element exists on the given layer. You supply the layer handle which can be a string of the layer name - as defined in the Room Editor - or the unique layer handle - as returned by the function layer_get_id(), as well the sequence element ID - as returned by layer_sequence_create() or by one of the layer element functions - and it will return true if the given element exists or false otherwise.
++
layer_sequence_exists(layer_id, sequence_element_id)
+Argument | +Type | +Description | +
---|---|---|
layer_ID | +String or Layer | +The unique ID or name of the layer to check | +
sequence_element_id | +Sequence Element ID | +The unique ID value of the sequence element to target | +
+
+
if (!layer_sequence_exists("Background", my_seq))
+ {
+ my_seq = layer_sequence_create("Background", 0, 0, seq_AnimatedBackground);
+ layer_sequence_pause(my_seq);
+ }
The above code checks to see if the given sequence element exists, and if it does not then it creates a new sequence on the given layer then pauses it.
++
+
+
With this function you can assign a sprite resource to a layer to be used in your project. You supply the layer handle (which you get when you create the layer using layer_create() or when you use the layer name along with layer_get_id()), a position within the room, and a sprite index (which would be the name of the sprite as shown in the Asset Browser), and it will be added to the layer. The function returns the unique ID value for the element, which can then be used in further layer functions for sprites.
--
layer_sprite_create(layer_id, x, y, sprite)
-Argument | -Type | -Description | -
---|---|---|
layer_id | -String or Layer | -The handle of the layer to target | -
x | -Real | -The x position to use | -
y | -Real | -The y position to use | -
sprite | -Sprite Asset | -The sprite index to be used | -
-
-
global.asset_layer = layer_create(10000);
-
- for (var i = 0; i< 10; i++;)
-
- {
-
- var _x = random(room_width);
-
- var _y = room_height - 100;
-
- global.asset_spr_trees[i] = layer_sprite_create(global.asset_layer, _x, _y, spr_Trees);
-
- }
The above code creates a new layer and then adds 10 new sprite elements to it, storing the ID of each element to an array.
--
-
-
With this function you can assign a sprite resource to a layer to be used in your project. You supply the layer handle (which you get when you create the layer using layer_create() or when you use the layer name along with layer_get_id()), a position within the room, and a sprite index (which would be the name of the sprite as shown in the Asset Browser), and it will be added to the layer. The function returns the unique ID value for the element, which can then be used in further layer functions for sprites.
++
layer_sprite_create(layer_id, x, y, sprite)
+Argument | +Type | +Description | +
---|---|---|
layer_id | +String or Layer | +The handle of the layer to target | +
x | +Real | +The x position to use | +
y | +Real | +The y position to use | +
sprite | +Sprite Asset | +The sprite index to be used | +
+
+
global.asset_layer = layer_create(10000);
+ for (var i = 0; i< 10; i++;)
+ {
+ var _x = random(room_width);
+ var _y = room_height - 100;
+ global.asset_spr_trees[i] = layer_sprite_create(global.asset_layer, _x, _y, spr_Trees);
+ }
The above code creates a new layer and then adds 10 new sprite elements to it, storing the ID of each element to an array.
++
+
+
This function will destroy the given sprite element. You supply the sprite ID (which you get when you create the sprite using layer_sprite_create() or when you use the layer handle along with layer_get_sprite_id()) and this will remove it. Note that this does not remove the layer, only the sprite from it, and if the sprite is one that has been added in the room editor, then the next time you leave the room and then return, the sprite will be recreated again. However if the room is persistent, the sprite will be removed unless room persistence is switched off again.
--
layer_sprite_destroy(sprite_element_id)
-Argument | -Type | -Description | -
---|---|---|
sprite_element_id | -Sprite Element ID | -The unique ID value of the sprite to be destroyed | -
-
N/A
--
var lay_id = layer_get_id("Asset_Trees");
-
- var spr_id = layer_sprite_get_id(lay_id, "graphic_254367CB");
-
-
- if (layer_sprite_exists(lay_id, spr_id))
-
- {
-
- layer_sprite_destroy(spr_id);
-
- }
The above code checks the layer "Asset_Trees" to see if the given sprite element exists and if it does, then it is destroyed (but not the layer).
--
-
-
This function will destroy the given sprite element. You supply the sprite ID (which you get when you create the sprite using layer_sprite_create() or when you use the layer handle along with layer_get_sprite_id()) and this will remove it. Note that this does not remove the layer, only the sprite from it, and if the sprite is one that has been added in the room editor, then the next time you leave the room and then return, the sprite will be recreated again. However if the room is persistent, the sprite will be removed unless room persistence is switched off again.
++
layer_sprite_destroy(sprite_element_id)
+Argument | +Type | +Description | +
---|---|---|
sprite_element_id | +Sprite Element ID | +The unique ID value of the sprite to be destroyed | +
+
N/A
++
var lay_id = layer_get_id("Asset_Trees");
+ var spr_id = layer_sprite_get_id(lay_id, "graphic_254367CB");
+
+ if (layer_sprite_exists(lay_id, spr_id))
+ {
+ layer_sprite_destroy(spr_id);
+ }
+
The above code checks the layer "Asset_Trees" to see if the given sprite element exists and if it does, then it is destroyed (but not the layer).
++
+
+
You can use this function to check and see if a sprite element exists on any given layer. You supply the layer handle (which you get when you create the layer using layer_create()) or the layer name (as a string - this will have a performance impact) and the sprite element ID (which you get when you create a sprite element using layer_sprite_create() or when you use the function layer_sprite_get_id()) and the function will return either true if the element exists, or false if it does not.
-This function works within the scope of the current target room - by default the room in which the function is called - which can be set using the function layer_set_target_room().
--
layer_sprite_exists(layer_id, sprite_element_id)
-Argument | -Type | -Description | -
---|---|---|
layer_id | -String or Layer | -The handle of the layer to target (or the layer name as a string) | -
sprite_element_id | -Sprite Element ID | -The unique ID value of the sprite element to check | -
-
-
var lay_id = layer_get_id("Asset_Trees");
-
- var spr_id = layer_sprite_get_id(lay_id, "graphic_254367CB");
-
-
- if (layer_sprite_exists(lay_id, spr_id))
-
- {
-
- layer_sprite_destroy(spr_id);
-
- }
The above code checks the layer "Asset_trees" to see if the given sprite element exists and if it does, then it is destroyed (but not the layer).
--
-
-
You can use this function to check and see if a sprite element exists on any given layer. You supply the layer handle (which you get when you create the layer using layer_create()) or the layer name (as a string - this will have a performance impact) and the sprite element ID (which you get when you create a sprite element using layer_sprite_create() or when you use the function layer_sprite_get_id()) and the function will return either true if the element exists, or false if it does not.
+This function works within the scope of the current target room - by default the room in which the function is called - which can be set using the function layer_set_target_room().
++
layer_sprite_exists(layer_id, sprite_element_id)
+Argument | +Type | +Description | +
---|---|---|
layer_id | +String or Layer | +The handle of the layer to target (or the layer name as a string) | +
sprite_element_id | +Sprite Element ID | +The unique ID value of the sprite element to check | +
+
+
var lay_id = layer_get_id("Asset_Trees");
+ var spr_id = layer_sprite_get_id(lay_id, "graphic_254367CB");
+
+ if (layer_sprite_exists(lay_id, spr_id))
+ {
+ layer_sprite_destroy(spr_id);
+ }
+
The above code checks the layer "Asset_trees" to see if the given sprite element exists and if it does, then it is destroyed (but not the layer).
++
+
+
This function can be used to get the alpha value of the sprite element. You give the sprite element ID (which you get when you create a sprite element using layer_sprite_create() or when you use the function layer_sprite_get_id()), and the function will return a value between 0 (fully transparent) and 1 (fully opaque).
--
layer_sprite_get_alpha(sprite_element_id);
-Argument | -Type | -Description | -
---|---|---|
sprite_element_id | -Sprite Element ID | -The unique ID value of the sprite element to get the information from | -
-
Real (from 0 to 1)
--
var lay_id = layer_get_id("sprite_sky");
-
- var spr_id = layer_sprite_get_id(lay_id, "Clouds");
-
- if (layer_sprite_get_alpha(spr_id) < 0.1)
-
- {
-
- layer_sprite_destroy(spr_id);
-
- }
The above code will get the layer handle for the layer named "sprite_sky" and then use that to get the ID of the sprite element on that layer. This ID is then used to check the element alpha and if it is less than 0.1, then the layer element is destroyed.
--
-
-
This function can be used to get the alpha value of the sprite element. You give the sprite element ID (which you get when you create a sprite element using layer_sprite_create() or when you use the function layer_sprite_get_id()), and the function will return a value between 0 (fully transparent) and 1 (fully opaque).
++
layer_sprite_get_alpha(sprite_element_id);
+Argument | +Type | +Description | +
---|---|---|
sprite_element_id | +Sprite Element ID | +The unique ID value of the sprite element to get the information from | +
+
Real (from 0 to 1)
++
var lay_id = layer_get_id("sprite_sky");
+ var spr_id = layer_sprite_get_id(lay_id, "Clouds");
+ if (layer_sprite_get_alpha(spr_id) < 0.1)
+ {
+ layer_sprite_destroy(spr_id);
+ }
The above code will get the layer handle for the layer named "sprite_sky" and then use that to get the ID of the sprite element on that layer. This ID is then used to check the element alpha and if it is less than 0.1, then the layer element is destroyed.
++
+
+
This function can be used to get the current angle for the sprite element. You give the sprite element ID (which you get when you create a sprite element using layer_sprite_create() or when you use the function layer_sprite_get_id()), and the function will return real value for the angle. This value will be between 0 and 360, where 0 represents right, 90 up, 180 left and 270 down.
--
layer_sprite_get_angle(sprite_element_id);
-Argument | -Type | -Description | -
---|---|---|
sprite_element_id | -Sprite Element ID | -The unique ID value of the sprite element to get the information from | -
-
-
var lay_id = layer_get_id("sprite_sky");
-
- var spr_id = layer_sprite_get_id(lay_id, "Clouds");
-
- if (layer_sprite_get_angle(spr_id) != 0)
-
- {
-
- layer_sprite_yscale(spr_id, 0);
-
- }
The above code will get the layer handle for the layer named "sprite_sky" and then use that to get the ID of the sprite element on that layer. This ID is then used to check the angle and if it is anything other than 0 it is set to 0.
--
-
-
This function can be used to get the current angle for the sprite element. You give the sprite element ID (which you get when you create a sprite element using layer_sprite_create() or when you use the function layer_sprite_get_id()), and the function will return real value for the angle. This value will be between 0 and 360, where 0 represents right, 90 up, 180 left and 270 down.
++
layer_sprite_get_angle(sprite_element_id);
+Argument | +Type | +Description | +
---|---|---|
sprite_element_id | +Sprite Element ID | +The unique ID value of the sprite element to get the information from | +
+
+
var lay_id = layer_get_id("sprite_sky");
+ var spr_id = layer_sprite_get_id(lay_id, "Clouds");
+ if (layer_sprite_get_angle(spr_id) != 0)
+ {
+ layer_sprite_yscale(spr_id, 0);
+ }
The above code will get the layer handle for the layer named "sprite_sky" and then use that to get the ID of the sprite element on that layer. This ID is then used to check the angle and if it is anything other than 0 it is set to 0.
++
+
+
This function can be used to get the blend colour of the sprite element. You give the sprite element ID (which you get when you create a sprite element using layer_sprite_create() or when you use the function layer_sprite_get_id()), and the function will return real value that represents the colour assigned.
--
layer_sprite_get_blend(sprite_element_id);
-Argument | -Type | -Description | -
---|---|---|
sprite_element_id | -Sprite Element ID | -The unique ID value of the sprite element to get the information from | -
-
-
var lay_id = layer_get_id("sprite_sky");
-
- var back_id = layer_sprite_get_id(lay_id, "Clouds");
-
- if (layer_sprite_get_blend(back_id) == c_white)
-
- {
-
- layer_sprite_blend(back_id, make_colour_rgb(random(255), random(255), 255));
-
- }
The above code will get the layer handle for the layer named "sprite_sky" and then use that to get the ID of the sprite element on that layer. This ID is then used to check the element blend colour and if it is equivalent to the constant c_white, then the element blend is set to a random colour.
--
-
-
This function can be used to get the blend colour of the sprite element. You give the sprite element ID (which you get when you create a sprite element using layer_sprite_create() or when you use the function layer_sprite_get_id()), and the function will return real value that represents the colour assigned.
++
layer_sprite_get_blend(sprite_element_id);
+Argument | +Type | +Description | +
---|---|---|
sprite_element_id | +Sprite Element ID | +The unique ID value of the sprite element to get the information from | +
+
+
var lay_id = layer_get_id("sprite_sky");
+ var back_id = layer_sprite_get_id(lay_id, "Clouds");
+ if (layer_sprite_get_blend(back_id) == c_white)
+ {
+ layer_sprite_blend(back_id, make_colour_rgb(random(255), random(255), 255));
+ }
The above code will get the layer handle for the layer named "sprite_sky" and then use that to get the ID of the sprite element on that layer. This ID is then used to check the element blend colour and if it is equivalent to the constant c_white, then the element blend is set to a random colour.
++
+
+
This function can be used to get the current image index value of the sprite element. You give the sprite element ID (which you get when you create a sprite element using layer_sprite_create() or when you use the function layer_sprite_get_id()), and the function will return real value that represents the image index being shown for the sprite. The function will return -1 if either the sprite element doesn't exist or the element doesn't have a valid sprite assigned to it.
--
layer_sprite_get_index(sprite_element_id);
-Argument | -Type | -Description | -
---|---|---|
sprite_element_id | -Sprite Element ID | -The unique ID value of the sprite element to get the information from | -
-
Real or -1
--
var lay_id = layer_get_id("sprite_sky");
-
- var spr_id = layer_sprite_get_id(lay_id, "Clouds");
-
- if (layer_sprite_get_index(spr_id) < 4)
-
- {
-
- layer_sprite_index(spr_id, 4);
-
- }
The above code will get the layer handle for the layer named "sprite_sky" and then use that to get the ID of the sprite element on that layer. This ID is then used to check if the image index for the element is less than 4, and if so it is set to 4.
--
-
-
This function can be used to get the current image index value of the sprite element. You give the sprite element ID (which you get when you create a sprite element using layer_sprite_create() or when you use the function layer_sprite_get_id()), and the function will return real value that represents the image index being shown for the sprite. The function will return -1 if either the sprite element doesn't exist or the element doesn't have a valid sprite assigned to it.
++
layer_sprite_get_index(sprite_element_id);
+Argument | +Type | +Description | +
---|---|---|
sprite_element_id | +Sprite Element ID | +The unique ID value of the sprite element to get the information from | +
+
Real or -1
++
var lay_id = layer_get_id("sprite_sky");
+ var spr_id = layer_sprite_get_id(lay_id, "Clouds");
+ if (layer_sprite_get_index(spr_id) < 4)
+ {
+ layer_sprite_index(spr_id, 4);
+ }
The above code will get the layer handle for the layer named "sprite_sky" and then use that to get the ID of the sprite element on that layer. This ID is then used to check if the image index for the element is less than 4, and if so it is set to 4.
++
+
+
This function can be used to get the current speed multiplier value of the sprite element. You give the sprite element ID (which you get when you create a sprite element using layer_sprite_create() or when you use the function layer_sprite_get_id()), and the function will return real value that represents the speed multiplier being used to animate the sprite. Default value is 1.
--
layer_sprite_get_speed(sprite_element_id);
-Argument | -Type | -Description | -
---|---|---|
sprite_element_id | -Sprite Element ID | -The unique ID value of the sprite element to get the information from | -
-
-
var lay_id = layer_get_id("sprite_sky");
-
- var spr_id = layer_sprite_get_id(lay_id, "Clouds");
-
- if (layer_sprite_get_speed(spr_id) > 0)
-
- {
-
- layer_sprite_speed(spr_id, 0);
-
- }
The above code will get the layer handle for the layer named "sprite_sky" and then use that to get the ID of the sprite element on that layer. This ID is then used to check the animation speed for the element and if it is greater than 0, it is set to 0.
--
-
-
This function can be used to get the current speed multiplier value of the sprite element. You give the sprite element ID (which you get when you create a sprite element using layer_sprite_create() or when you use the function layer_sprite_get_id()), and the function will return real value that represents the speed multiplier being used to animate the sprite. Default value is 1.
++
layer_sprite_get_speed(sprite_element_id);
+Argument | +Type | +Description | +
---|---|---|
sprite_element_id | +Sprite Element ID | +The unique ID value of the sprite element to get the information from | +
+
+
var lay_id = layer_get_id("sprite_sky");
+ var spr_id = layer_sprite_get_id(lay_id, "Clouds");
+ if (layer_sprite_get_speed(spr_id) > 0)
+ {
+ layer_sprite_speed(spr_id, 0);
+ }
The above code will get the layer handle for the layer named "sprite_sky" and then use that to get the ID of the sprite element on that layer. This ID is then used to check the animation speed for the element and if it is greater than 0, it is set to 0.
++
+
+
This function can be used to get the current sprite index of the sprite element. You give the sprite element ID (which you get when you create a sprite element using layer_sprite_create or when you use the function layer_sprite_get_id), and the function will return a real value that represents the sprite index being shown. If the element has no sprite assigned, the function will return -1.
--
layer_sprite_get_sprite(sprite_element_id);
-Argument | -Type | -Description | -
---|---|---|
sprite_element_id | -Sprite Element ID | -The unique ID value of the sprite element to get the information from | -
-
Sprite Asset or -1
--
var lay_id = layer_get_id("sprite_sky");
-
- var spr_id = layer_sprite_get_id(lay_id, "Clouds");
-
- if layer_sprite_get_sprite(spr_id) != spr_Clouds
-
- {
-
- layer_sprite_change(spr_id, spr_Clouds);
-
- }
The above code will get the layer handle for the layer named "sprite_sky" and then use that to get the ID of the sprite element on that layer. This ID is then used to check the sprite assigned to the element, setting it to the sprite "spr_Clouds" if it is not already.
--
-
-
This function can be used to get the current sprite index of the sprite element. You give the sprite element ID (which you get when you create a sprite element using layer_sprite_create or when you use the function layer_sprite_get_id), and the function will return a real value that represents the sprite index being shown. If the element has no sprite assigned, the function will return -1.
++
layer_sprite_get_sprite(sprite_element_id);
+Argument | +Type | +Description | +
---|---|---|
sprite_element_id | +Sprite Element ID | +The unique ID value of the sprite element to get the information from | +
+
Sprite Asset or -1
++
var lay_id = layer_get_id("sprite_sky");
+ var spr_id = layer_sprite_get_id(lay_id, "Clouds");
+ if layer_sprite_get_sprite(spr_id) != spr_Clouds
+ {
+ layer_sprite_change(spr_id, spr_Clouds);
+ }
The above code will get the layer handle for the layer named "sprite_sky" and then use that to get the ID of the sprite element on that layer. This ID is then used to check the sprite assigned to the element, setting it to the sprite "spr_Clouds" if it is not already.
++
+
+
This function can be used to get the x position of the sprite element in the room. You give the sprite element ID (which you get when you create a sprite element using layer_sprite_create() or when you use the function layer_sprite_get_id()), and the function will return the x position value.
--
layer_sprite_get_x(sprite_element_id);
-Argument | -Type | -Description | -
---|---|---|
sprite_element_id | -Sprite Element ID | -The unique ID value of the sprite element to get the information from | -
-
-
var lay_id = layer_get_id("sprite_sky");
-
- var spr_id = layer_sprite_get_id(lay_id, "Clouds");
-
- if (layer_sprite_get_x(spr_id) < 0)
-
- {
-
- layer_sprite_x(spr_id, room_width);
-
- }
The above code will get the layer handle for the layer named "sprite_sky" and then use that to get the ID of the sprite element on that layer. This ID is then used to check the element x position and if it is less than 0, then the layer element is moved to a different x position.
--
-
-
This function can be used to get the x position of the sprite element in the room. You give the sprite element ID (which you get when you create a sprite element using layer_sprite_create() or when you use the function layer_sprite_get_id()), and the function will return the x position value.
++
layer_sprite_get_x(sprite_element_id);
+Argument | +Type | +Description | +
---|---|---|
sprite_element_id | +Sprite Element ID | +The unique ID value of the sprite element to get the information from | +
+
+
var lay_id = layer_get_id("sprite_sky");
+ var spr_id = layer_sprite_get_id(lay_id, "Clouds");
+ if (layer_sprite_get_x(spr_id) < 0)
+ {
+ layer_sprite_x(spr_id, room_width);
+ }
The above code will get the layer handle for the layer named "sprite_sky" and then use that to get the ID of the sprite element on that layer. This ID is then used to check the element x position and if it is less than 0, then the layer element is moved to a different x position.
++
+
+
This function can be used to get the current scale multiplier along the x axis for the sprite element. You give the sprite element ID (which you get when you create a sprite element using layer_sprite_create() or when you use the function layer_sprite_get_id()), and the function will return real value for the x scale, where 1 is no scaling.
--
layer_sprite_get_xscale(sprite_element_id);
-Argument | -Type | -Description | -
---|---|---|
sprite_element_id | -Sprite Element ID | -The unique ID value of the sprite element to get the information from | -
-
-
var lay_id = layer_get_id("sprite_sky");
-
- var spr_id = layer_sprite_get_id(lay_id, "Clouds");
-
- if (layer_sprite_get_xscale(spr_id) != 1)
-
- {
-
- layer_sprite_xscale(spr_id, 1);
-
- }
The above code will get the layer handle for the layer named "sprite_sky" and then use that to get the ID of the sprite element on that layer. This ID is then used to check the xscale value and if it is anything other than 1 it is set to 1.
--
-
-
This function can be used to get the current scale multiplier along the x axis for the sprite element. You give the sprite element ID (which you get when you create a sprite element using layer_sprite_create() or when you use the function layer_sprite_get_id()), and the function will return real value for the x scale, where 1 is no scaling.
++
layer_sprite_get_xscale(sprite_element_id);
+Argument | +Type | +Description | +
---|---|---|
sprite_element_id | +Sprite Element ID | +The unique ID value of the sprite element to get the information from | +
+
+
var lay_id = layer_get_id("sprite_sky");
+ var spr_id = layer_sprite_get_id(lay_id, "Clouds");
+ if (layer_sprite_get_xscale(spr_id) != 1)
+ {
+ layer_sprite_xscale(spr_id, 1);
+ }
The above code will get the layer handle for the layer named "sprite_sky" and then use that to get the ID of the sprite element on that layer. This ID is then used to check the xscale value and if it is anything other than 1 it is set to 1.
++
+
+
This function can be used to get the y position of the sprite element in the room. You give the sprite element ID (which you get when you create a sprite element using layer_sprite_create() or when you use the function layer_sprite_get_id()), and the function will return the y position value.
--
layer_sprite_get_y(sprite_element_id);
-Argument | -Type | -Description | -
---|---|---|
sprite_element_id | -Sprite Element ID | -The unique ID value of the sprite element to get the information from | -
-
-
var lay_id = layer_get_id("sprite_sky");
-
- var spr_id = layer_sprite_get_id(lay_id, "Clouds");
-
- if (layer_sprite_get_y(spr_id) < 0)
-
- {
-
- layer_sprite_y(spr_id, room_height);
-
- }
The above code will get the layer handle for the layer named "sprite_sky" and then use that to get the ID of the sprite element on that layer. This ID is then used to check the element y position and if it is less than 0, then the layer element is moved to a different y position.
--
-
-
This function can be used to get the y position of the sprite element in the room. You give the sprite element ID (which you get when you create a sprite element using layer_sprite_create() or when you use the function layer_sprite_get_id()), and the function will return the y position value.
++
layer_sprite_get_y(sprite_element_id);
+Argument | +Type | +Description | +
---|---|---|
sprite_element_id | +Sprite Element ID | +The unique ID value of the sprite element to get the information from | +
+
+
var lay_id = layer_get_id("sprite_sky");
+ var spr_id = layer_sprite_get_id(lay_id, "Clouds");
+ if (layer_sprite_get_y(spr_id) < 0)
+ {
+ layer_sprite_y(spr_id, room_height);
+ }
The above code will get the layer handle for the layer named "sprite_sky" and then use that to get the ID of the sprite element on that layer. This ID is then used to check the element y position and if it is less than 0, then the layer element is moved to a different y position.
++
+
+
This function can be used to get the current scale multiplier along the y axis for the sprite element. You give the sprite element ID (which you get when you create a sprite element using layer_sprite_create() or when you use the function layer_sprite_get_id()), and the function will return real value for the y scale, where 1 is no scaling.
--
layer_sprite_get_yscale(sprite_element_id);
-Argument | -Type | -Description | -
---|---|---|
sprite_element_id | -Sprite Element ID | -The unique ID value of the sprite element to get the information from | -
-
-
var lay_id = layer_get_id("sprite_sky");
-
- var spr_id = layer_sprite_get_id(lay_id, "Clouds");
-
- if (layer_sprite_get_yscale(spr_id) != 1)
-
- {
-
- layer_sprite_yscale(spr_id, 1);
-
- }
The above code will get the layer handle for the layer named "sprite_sky" and then use that to get the ID of the sprite element on that layer. This ID is then used to check the yscale value and if it is anything other than 1 it is set to 1.
--
-
-
This function can be used to get the current scale multiplier along the y axis for the sprite element. You give the sprite element ID (which you get when you create a sprite element using layer_sprite_create() or when you use the function layer_sprite_get_id()), and the function will return real value for the y scale, where 1 is no scaling.
++
layer_sprite_get_yscale(sprite_element_id);
+Argument | +Type | +Description | +
---|---|---|
sprite_element_id | +Sprite Element ID | +The unique ID value of the sprite element to get the information from | +
+
+
var lay_id = layer_get_id("sprite_sky");
+ var spr_id = layer_sprite_get_id(lay_id, "Clouds");
+ if (layer_sprite_get_yscale(spr_id) != 1)
+ {
+ layer_sprite_yscale(spr_id, 1);
+ }
The above code will get the layer handle for the layer named "sprite_sky" and then use that to get the ID of the sprite element on that layer. This ID is then used to check the yscale value and if it is anything other than 1 it is set to 1.
++
+
+
This function will destroy the given tile map element.
-You supply the tile map ID (which you get when you create the tile map using layer_tilemap_create() or when you use the layer handle along with layer_get_tilemap_id()) and this will remove it.
-This does not remove the layer, only the tile map from it. If the tile map is one that has been added in the Room Editor, the next time you leave the room and then return, the tile map will be created again. If the room is persistent, however, the tile map will be removed unless room persistence is switched off again.
--
layer_tilemap_destroy(tilemap_element_id);
-Argument | -Type | -Description | -
---|---|---|
tilemap_element_id | -Tile Map Element ID | -The unique ID value of the tile map to be destroyed | -
-
N/A
--
var lay_id = layer_get_id("Tiles_trees");
-
- var tile_id = layer_tilemap_get_id(lay_id);
-
- if (layer_tilemap_exists(lay_id, tile_id))
-
- {
-
- layer_tilemap_destroy(tile_id);
-
- }
The above code checks the layer "Tiles_trees" to see if the given tile map element exists and if it does, then it is destroyed (but not the layer).
--
-
This function will destroy the given tile map element.
+You supply the tile map ID (which you get when you create the tile map using layer_tilemap_create() or when you use the layer handle along with layer_get_tilemap_id()) and this will remove it.
+This does not remove the layer, only the tile map from it. If the tile map is one that has been added in the Room Editor, the next time you leave the room and then return, the tile map will be created again. If the room is persistent, however, the tile map will be removed unless room persistence is switched off again.
++
layer_tilemap_destroy(tilemap_element_id);
+Argument | +Type | +Description | +
---|---|---|
tilemap_element_id | +Tile Map Element ID | +The unique ID value of the tile map to be destroyed | +
+
N/A
++
var lay_id = layer_get_id("Tiles_trees");
+ var tile_id = layer_tilemap_get_id(lay_id);
+ if (layer_tilemap_exists(lay_id, tile_id))
+ {
+ layer_tilemap_destroy(tile_id);
+ }
The above code checks the layer "Tiles_trees" to see if the given tile map element exists and if it does, then it is destroyed (but not the layer).
++
+
You can use this function to check and see if a tile map element exists on any given layer.
-You supply the layer handle (which you get when you create the layer using layer_create()) or the layer name (as a string - this will have a performance impact) and the tile map element ID (which you get when you create a tile map element using layer_tilemap_create() or when you use the function layer_tilemap_get_id()) and the function will return either true if the element exists, or false if it does not.
-This function works within the scope of the current target room - by default the room in which the function is called - which can be set using the function layer_set_target_room().
--
layer_tilemap_exists(layer_id, tilemap_element_id)
-Argument | -Type | -Description | -
---|---|---|
layer_id | -String or Layer ID | -The handle of the layer to target (or the layer name as a string) | -
tilemap_element_id | -Tile Map Element ID | -The unique ID value of the tile map element to check | -
-
-
var lay_id = layer_get_id("tilemap_trees");
-
- if (layer_tilemap_exists(lay_id, global.Treestilemap))
-
- {
-
- layer_tilemap_destroy(lay_id, global.Treestilemap);
-
- }
The above code checks the layer "tilemap_trees" to see if the given tile map element exists and if it does, then it is destroyed (but not the layer).
--
-
You can use this function to check and see if a tile map element exists on any given layer.
+You supply the layer handle (which you get when you create the layer using layer_create()) or the layer name (as a string - this will have a performance impact) and the tile map element ID (which you get when you create a tile map element using layer_tilemap_create() or when you use the function layer_tilemap_get_id()) and the function will return either true if the element exists, or false if it does not.
+This function works within the scope of the current target room - by default the room in which the function is called - which can be set using the function layer_set_target_room().
++
layer_tilemap_exists(layer_id, tilemap_element_id)
+Argument | +Type | +Description | +
---|---|---|
layer_id | +String or Layer | +The handle of the layer to target (or the layer name as a string) | +
tilemap_element_id | +Tile Map Element ID | +The unique ID value of the tile map element to check | +
+
+
var lay_id = layer_get_id("tilemap_trees");
+ if (layer_tilemap_exists(lay_id, global.Treestilemap))
+ {
+ layer_tilemap_destroy(lay_id, global.Treestilemap);
+ }
The above code checks the layer "tilemap_trees" to see if the given tile map element exists and if it does, then it is destroyed (but not the layer).
++
+
The format of the returned struct is as follows:
room_info_struct =
{
- instances:
- [
- {/* Instance Info Struct */},
- {/* Instance Info Struct */},
- ],
- layers:
- [
- {
- elements:
- [
- {/* Layer Element Info Struct */},
- {
- /* Example */
- type: layerelementtype_tilemap,
- tiles: [/* Tile Map Data */]
- }
- ]
- },
- ],
- views:
- [
- {/* View Info Struct */},
- ]
+ instances:
+ [
+ {/* Instance Info Struct */},
+ {/* Instance Info Struct */},
+ ],
+ layers:
+ [
+ {
+ elements:
+ [
+ {/* Layer Element Info Struct */},
+ {
+ /* Example */
+ type: layerelementtype_tilemap,
+ tiles: [/* Tile Map Data */]
+ }
+ ]
+ },
+ ],
+ views:
+ [
+ {/* View Info Struct */},
+ ]
}
The tables below list all the possible structs that can be contained in the returned struct:
@@ -144,7 +144,7 @@This type of struct represents one instance in the room.
These structs are found in the instances array, which is part of the main struct returned by the function.
-id | -Object Instance | +Object Instance | The instance ID |
object_index | -String | +String | The name of the object this is an instance of (use asset_get_index to get the actual object) |
x | -Real | +Real | The x coordinate of the instance's position |
y | -Real | +Real | The y coordinate of the instance's position |
xscale | -Real | +Real | The x scale of the instance |
yscale | -Real | +Real | The y scale of the instance |
angle | -Real | +Real | The rotation angle of the instance |
image_index | -Real | +Real | The image index used by the instance |
image_speed | -Real | +Real | The image speed of the instance |
colour | -Colour | +Colour | The blend colour used to draw the instance |
creation_code | -Script Function | +Script Function | The index of the script function that contains the instance's creation code |
pre_creation_code | -Script Function | +Script Function | The index of the script function that holds the pre-creation code for this specific instance, i.e. the overrides for its Object Variables as set in the Room Editor. See: Pre-creation Code |
Argument | -Type | -Description | -
---|---|---|
index | -DS Grid | -This handle of the grid to destroy. | -
-
N/A
--
if (lives == 0)
-
- {
-
- ds_grid_destroy(Wall_Grid);
-
- Wall_Grid = -1;
-
- room_goto(rm_Menu);
-
- }
The above code will check the value of the built in global variable lives and if it is 0, it destroys the DS grid referenced in the variable Wall_Grid and then changes rooms.
--
-
This function will remove the given grid data structure from memory, freeing up the resources it was using and removing all values that it contained. This function should always be used when you are finished using the DS grid to prevent memory leaks that can slow down and crash your game.
++
ds_grid_destroy(index);
+Argument | +Type | +Description | +
---|---|---|
index | +DS Grid | +This handle of the grid to destroy. | +
+
N/A
++
if (lives == 0)
+ {
+ ds_grid_destroy(Wall_Grid);
+ Wall_Grid = -1;
+ room_goto(rm_Menu);
+ }
The above code will check the value of the built in global variable lives and if it is 0, it destroys the DS grid referenced in the variable Wall_Grid and then changes rooms.
++
+
This function will return the height of the given grid. This value is the number of cells the grid has along the y-axis and is always an integer, as shown in the image below:
- --
ds_grid_height(index);
-Argument | -Type | -Description | -
---|---|---|
index | -- | This handle of the grid to find the height of. | -
-
-
-
for (var i = 0; i < ds_grid_width(grid); ++i)
-
- {
-
- for (var j = 0; j < ds_grid_height(grid); ++j)
-
- {
-
- if (ds_grid_get(grid, i, j) == 1)
-
- {
-
- instance_create_Layer(i * 32, j * 32, "Walls", obj_Wall);
-
- }
-
- }
-
- }
The above code will loop through the DS grid indexed in the variable "grid" and if the value found in any specific cell is equal to 1, it will then create an instance of "obj_Wall" at the appropriate position within the room.
--
-
-
This function will return the height of the given grid. This value is the number of cells the grid has along the y-axis and is always an integer, as shown in the image below:
+ ++
ds_grid_height(index);
+Argument | +Type | +Description | +
---|---|---|
index | +DS Grid | +This handle of the grid to find the height of. | +
+
+
for (var i = 0; i < ds_grid_width(grid); ++i)
+ {
+ for (var j = 0; j < ds_grid_height(grid); ++j)
+ {
+ if (ds_grid_get(grid, i, j) == 1)
+ {
+ instance_create_Layer(i * 32, j * 32, "Walls", obj_Wall);
+ }
+ }
+ }
The above code will loop through the DS grid indexed in the variable "grid" and if the value found in any specific cell is equal to 1, it will then create an instance of "obj_Wall" at the appropriate position within the room.
++
+
+
This function can be used to set a given cell within the given DS grid to any value, which can be a real number or a string. The image below illustrates this:
- -ds_grid_set(index, x, y, value);
-Argument | -Type | -Description | -
---|---|---|
index | -- | This handle of the grid. | -
x | -- | The x position of the cell to set. | -
y | -- | The y position of the cell to set. | -
value | -- | The value with which to set the cell. | -
-
-
-
grid = ds_grid_create(5, 5);
-
- var i = 0;
-
- var j = 0;
-
-
- repeat (ds_grid_width(grid))
-
- {
-
- repeat (ds_grid_height(grid))
-
- {
-
- ds_grid_set(grid, i, j, irandom(9));
-
- j += 1;
-
- }
-
-
- j = 0;
-
- i += 1;
-
- }
The above code creates a grid and stores its index in the variable "grid". It then populates this grid with random integers from 0 to 9.
--
-
-
This function can be used to set a given cell within the given DS grid to any value, which can be a real number or a string. The image below illustrates this:
+ +ds_grid_set(index, x, y, value);
+Argument | +Type | +Description | +
---|---|---|
index | +DS Grid | +This handle of the grid. | +
x | +Real | +The x position of the cell to set. | +
y | +Real | +The y position of the cell to set. | +
value | +Any | +The value with which to set the cell. | +
+
N/A
++
grid = ds_grid_create(5, 5);
+ var i = 0;
+ var j = 0;
+
+ repeat (ds_grid_width(grid))
+ {
+ repeat (ds_grid_height(grid))
+ {
+ ds_grid_set(grid, i, j, irandom(9));
+ j += 1;
+ }
+
+ j = 0;
+ i += 1;
+ }
+
The above code creates a grid and stores its index in the variable "grid". It then populates this grid with random integers from 0 to 9.
++
+
+
With this function you can check to see if a specific value (real or string) is present within a circular area of a given DS grid. If it is present the function will return true otherwise it will return false.
--
ds_grid_value_disk_exists(index, xm, ym, r, val);
-Argument | -Type | -Description | -
---|---|---|
index | -- | The handle of the grid. | -
xm | -- | The x position of the disk on the grid. | -
ym | -- | The y position of the disk on the grid. | -
r | -- | The radius of the disk on the grid. | -
val | -- | The value to find. | -
-
-
-
if (ds_grid_value_disk_exists(grid, 5, 5, 5, val))
-
- {
-
- xpos = ds_grid_value_disk_x(grid, 5, 5, 5, val);
-
- ypos = ds_grid_value_disk_y(grid, 5, 5, 5, val);
-
- }
The above code checks a DS grid for a specific value within a disk region. if it is found, it then stores the x and y position of the value in two variables for later use.
--
-
-
With this function you can check to see if a specific value (real or string) is present within a circular area of a given DS grid. If it is present the function will return true otherwise it will return false.
++
ds_grid_value_disk_exists(index, xm, ym, r, val);
+Argument | +Type | +Description | +
---|---|---|
index | +DS Grid | +The handle of the grid. | +
xm | +Real | +The x position of the disk on the grid. | +
ym | +Real | +The y position of the disk on the grid. | +
r | +Real | +The radius of the disk on the grid. | +
val | +Any | +The value to find. | +
+
+
if (ds_grid_value_disk_exists(grid, 5, 5, 5, val))
+ {
+ xpos = ds_grid_value_disk_x(grid, 5, 5, 5, val);
+ ypos = ds_grid_value_disk_y(grid, 5, 5, 5, val);
+ }
The above code checks a DS grid for a specific value within a disk region. if it is found, it then stores the x and y position of the value in two variables for later use.
++
+
+
With this function you can get the x coordinate (within the given grid disc-shaped region) of the value being searched for. You give the DS grid index (as returned by ds_grid_create()) along with the x/y positions for the center cell of the disk. Then you give the radius (as an integer value) around the center cell to search, before supplying the value to search for. If the value being searched for does not exist, then the function will return -1.
--
ds_grid_value_disk_x(index, xm, ym, r, val);
-Argument | -Type | -Description | -
---|---|---|
index | -- | The handle of the grid. | -
xm | -- | The x position of the disk on the grid. | -
ym | -- | The y position of the disk on the grid. | -
r | -- | The radius of the disk on the grid. | -
val | -- | The value to find. | -
-
-
-
if (ds_grid_value_disk_exists(grid, 5, 5, 5, val))
-
- {
-
- xpos = ds_grid_value_disk_x(grid, 5, 5, 5, val);
-
- ypos = ds_grid_value_disk_y(grid, 5, 5, 5, val);
-
- }
The above code checks a ds_grid for a specific value within a disk region. if it is found, it then stores the x and y position of the value in two variables for later use.
--
-
-
With this function you can get the x coordinate (within the given grid disc-shaped region) of the value being searched for. You give the DS grid index (as returned by ds_grid_create()) along with the x/y positions for the center cell of the disk. Then you give the radius (as an integer value) around the center cell to search, before supplying the value to search for. If the value being searched for does not exist, then the function will return -1.
++
ds_grid_value_disk_x(index, xm, ym, r, val);
+Argument | +Type | +Description | +
---|---|---|
index | +DS Grid | +The handle of the grid. | +
xm | +Real | +The x position of the disk on the grid. | +
ym | +Real | +The y position of the disk on the grid. | +
r | +Real | +The radius of the disk on the grid. | +
val | +Any | +The value to find. | +
+
+
if (ds_grid_value_disk_exists(grid, 5, 5, 5, val))
+ {
+ xpos = ds_grid_value_disk_x(grid, 5, 5, 5, val);
+ ypos = ds_grid_value_disk_y(grid, 5, 5, 5, val);
+ }
The above code checks a ds_grid for a specific value within a disk region. if it is found, it then stores the x and y position of the value in two variables for later use.
++
+
+
With this function you can get the y coordinate (within the given grid disc-shaped region) of the value being searched for. You give the DS grid index (as returned by ds_grid_create()) along with the x/y positions for the center cell of the disk. Then you give the radius (as an integer value) around the center cell to search, before supplying the value to search for. If the value being searched for does not exist, then the function will return -1.
--
ds_grid_value_disk_y(index, xm, ym, r, val);
-Argument | -Type | -Description | -
---|---|---|
index | -- | The handle of the grid. | -
xm | -- | The x position of the disk on the grid. | -
ym | -- | The y position of the disk on the grid. | -
r | -- | The radius of the disk on the grid. | -
val | -- | The value to find. | -
-
-
-
if (ds_grid_value_disk_exists(grid, 5, 5, 5, val))
-
- {
-
- xpos = ds_grid_value_disk_x(grid, 5, 5, 5, val);
-
- ypos = ds_grid_value_disk_y(grid, 5, 5, 5, val);
-
- }
The above code checks a DS grid for a specific value within a disk region. if it is found, it then stores the x and y position of the value in two variables for later use.
--
-
-
With this function you can get the y coordinate (within the given grid disc-shaped region) of the value being searched for. You give the DS grid index (as returned by ds_grid_create()) along with the x/y positions for the center cell of the disk. Then you give the radius (as an integer value) around the center cell to search, before supplying the value to search for. If the value being searched for does not exist, then the function will return -1.
++
ds_grid_value_disk_y(index, xm, ym, r, val);
+Argument | +Type | +Description | +
---|---|---|
index | +DS Grid | +The handle of the grid. | +
xm | +Real | +The x position of the disk on the grid. | +
ym | +Real | +The y position of the disk on the grid. | +
r | +Real | +The radius of the disk on the grid. | +
val | +Any | +The value to find. | +
+
+
if (ds_grid_value_disk_exists(grid, 5, 5, 5, val))
+ {
+ xpos = ds_grid_value_disk_x(grid, 5, 5, 5, val);
+ ypos = ds_grid_value_disk_y(grid, 5, 5, 5, val);
+ }
The above code checks a DS grid for a specific value within a disk region. if it is found, it then stores the x and y position of the value in two variables for later use.
++
+
+
With this function you can check to see if a specific value (real or string) is present within a rectangular area of a given DS grid. If it is present the function will return true otherwise it will return false.
--
ds_grid_value_exists(index, x1, y1, x2, y2, val);
-Argument | -Type | -Description | -
---|---|---|
index | -- | The handle of the grid. | -
x1 | -- | The x position of the left of the region in the grid. | -
y1 | -- | The y position of the top of the region in the grid. | -
x2 | -- | The x position of the right of the region in the grid. | -
y2 | -- | The y position of the bottom of the region in the grid. | -
val | -- | The value to find. | -
-
-
-
if (ds_grid_value_exists(grid, 0, 1, 5, 6, val))
-
- {
-
- xpos = ds_grid_value_x(grid, 0, 1, 5, 6, val);
-
- ypos = ds_grid_value_y(grid, 0, 1, 5, 6, val);
-
- }
The above code checks a DS grid for a specific value within a rectangular region. if it is found, it then stores the x and y position of the value in two variables for later use.
--
-
-
With this function you can check to see if a specific value (real or string) is present within a rectangular area of a given DS grid. If it is present the function will return true otherwise it will return false.
++
ds_grid_value_exists(index, x1, y1, x2, y2, val);
+Argument | +Type | +Description | +
---|---|---|
index | +DS Grid | +The handle of the grid. | +
x1 | +Real | +The x position of the left of the region in the grid. | +
y1 | +Real | +The y position of the top of the region in the grid. | +
x2 | +Real | +The x position of the right of the region in the grid. | +
y2 | +Real | +The y position of the bottom of the region in the grid. | +
val | +Any | +The value to find. | +
+
+
if (ds_grid_value_exists(grid, 0, 1, 5, 6, val))
+ {
+ xpos = ds_grid_value_x(grid, 0, 1, 5, 6, val);
+ ypos = ds_grid_value_y(grid, 0, 1, 5, 6, val);
+ }
The above code checks a DS grid for a specific value within a rectangular region. if it is found, it then stores the x and y position of the value in two variables for later use.
++
+
+
With this function you can get the x coordinate (within the given rectangular grid region) of the value being searched for. You give the DS grid index (as returned by ds_grid_create()) along with the x/y positions for the top left and bottom right corners of the grid region to search, before supplying the value to search for. If the value being searched for does not exist, then the function will return -1.
--
ds_grid_value_x(index, x1, y1, x2, y2, val);
-Argument | -Type | -Description | -
---|---|---|
index | -- | The handle of the grid. | -
x1 | -- | The x position of the left of the region in the grid, from 0 to (grid width - 1). | -
y1 | -- | The y position of the top of the region in the grid, from 0 to (grid height - 1). | -
x2 | -- | The x position of the right of the region in the grid, from 0 to (grid width - 1). | -
y2 | -- | The y position of the bottom of the region in the grid, from 0 to (grid height - 1). | -
val | -- | The value to find. | -
-
-
-
if (ds_grid_value_exists(grid, 0, 1, 5, 6, val))
-
- {
-
- xpos = ds_grid_value_x(grid, 0, 1, 5, 6, val);
-
- ypos = ds_grid_value_y(grid, 0, 1, 5, 6, val);
-
- }
The above code checks a ds_grid for a specific value within a rectangular region. if it is found, it then stores the x and y position of the value in two variables for later use.
--
-
-
With this function you can get the x coordinate (within the given rectangular grid region) of the value being searched for. You give the DS grid index (as returned by ds_grid_create()) along with the x/y positions for the top left and bottom right corners of the grid region to search, before supplying the value to search for. If the value being searched for does not exist, then the function will return -1.
++
ds_grid_value_x(index, x1, y1, x2, y2, val);
+Argument | +Type | +Description | +
---|---|---|
index | +DS Grid | +The handle of the grid. | +
x1 | +Real | +The x position of the left of the region in the grid, from 0 to (grid width - 1). | +
y1 | +Real | +The y position of the top of the region in the grid, from 0 to (grid height - 1). | +
x2 | +Real | +The x position of the right of the region in the grid, from 0 to (grid width - 1). | +
y2 | +Real | +The y position of the bottom of the region in the grid, from 0 to (grid height - 1). | +
val | +Any | +The value to find. | +
+
+
if (ds_grid_value_exists(grid, 0, 1, 5, 6, val))
+ {
+ xpos = ds_grid_value_x(grid, 0, 1, 5, 6, val);
+ ypos = ds_grid_value_y(grid, 0, 1, 5, 6, val);
+ }
The above code checks a ds_grid for a specific value within a rectangular region. if it is found, it then stores the x and y position of the value in two variables for later use.
++
+
+
With this function you can get the y coordinate (within the given rectangular grid region) of the value being searched for. You give the DS grid index (as returned by ds_grid_create()) along with the x/y positions for the top left and bottom right corners of the grid region to search, before supplying the value to search for. If the value being searched for does not exist, then the function will return -1.
--
ds_grid_value_y(index, x1, y1, x2, y2, val);
-Argument | -Type | -Description | -
---|---|---|
index | -- | The handle of the grid. | -
x1 | -- | The x position of the left of the region in the grid, from 0 to (grid width - 1). | -
y1 | -- | The y position of the top of the region in the grid, from 0 to (grid height - 1). | -
x2 | -- | The x position of the right of the region in the grid, from 0 to (grid width - 1). | -
y2 | -- | The y position of the bottom of the region in the grid, from 0 to (grid height - 1) | -
val | -- | The value to find. | -
-
-
-
if (ds_grid_value_exists(grid, 0, 1, 5, 6, val))
-
- {
-
- xpos = ds_grid_value_x(grid, 0, 1, 5, 6, val);
-
- ypos = ds_grid_value_y(grid, 0, 1, 5, 6, val);
-
- }
The above code checks a ds_grid for a specific value within a rectangular region. if it is found, it then stores the x and y position of the value in two variables for later use.
--
-
-
With this function you can get the y coordinate (within the given rectangular grid region) of the value being searched for. You give the DS grid index (as returned by ds_grid_create()) along with the x/y positions for the top left and bottom right corners of the grid region to search, before supplying the value to search for. If the value being searched for does not exist, then the function will return -1.
++
ds_grid_value_y(index, x1, y1, x2, y2, val);
+Argument | +Type | +Description | +
---|---|---|
index | +DS Grid | +The handle of the grid. | +
x1 | +Real | +The x position of the left of the region in the grid, from 0 to (grid width - 1). | +
y1 | +Real | +The y position of the top of the region in the grid, from 0 to (grid height - 1). | +
x2 | +Real | +The x position of the right of the region in the grid, from 0 to (grid width - 1). | +
y2 | +Real | +The y position of the bottom of the region in the grid, from 0 to (grid height - 1) | +
val | +Any | +The value to find. | +
+
+
if (ds_grid_value_exists(grid, 0, 1, 5, 6, val))
+ {
+ xpos = ds_grid_value_x(grid, 0, 1, 5, 6, val);
+ ypos = ds_grid_value_y(grid, 0, 1, 5, 6, val);
+ }
The above code checks a ds_grid for a specific value within a rectangular region. if it is found, it then stores the x and y position of the value in two variables for later use.
++
+
+
This function will return the width of the given grid. This value is the number of cells the grid has along the x-axis and is always an integer, as shown in the image below:
- -ds_grid_width(index);
-Argument | -Type | -Description | -
---|---|---|
index | -- | This handle of the grid to find the width of. | -
-
-
-
for (var i = 0; i < ds_grid_width(grid); ++i)
-
- {
-
- for (var j = 0; j < ds_grid_height(grid); ++j)
-
- {
-
- if (ds_grid_get(grid, i, j) == 1)
-
- {
-
- instance_create_layer(i * 32, j * 32, "Walls", obj_Wall);
-
- }
-
- }
-
- }
The above code will loop through the DS grid indexed in the variable "grid" and if the value found in any specific cell is equal to 1, it will then create an instance of "obj_Wall" at the appropriate position within the room.
--
-
-
This function will return the width of the given grid. This value is the number of cells the grid has along the x-axis and is always an integer, as shown in the image below:
+ +ds_grid_width(index);
+Argument | +Type | +Description | +
---|---|---|
index | +DS Grid | +This handle of the grid to find the width of. | +
+
+
for (var i = 0; i < ds_grid_width(grid); ++i)
+ {
+ for (var j = 0; j < ds_grid_height(grid); ++j)
+ {
+ if (ds_grid_get(grid, i, j) == 1)
+ {
+ instance_create_layer(i * 32, j * 32, "Walls", obj_Wall);
+ }
+ }
+ }
The above code will loop through the DS grid indexed in the variable "grid" and if the value found in any specific cell is equal to 1, it will then create an instance of "obj_Wall" at the appropriate position within the room.
++
+
+
With this function you can clear all data from the given list data-structure. This does NOT destroy the data-structure (for that you should use ds_list_destroy()) it only wipes all data from it and makes the list empty (zero in size). Note that clearing a list will de-reference any data structures stored in it giving a memory leak, so you would need to go through the list and destroy all data structure items manually before clearing it to prevent this. The only time this is not required is when you have flagged any items in the list as another DS list or as a DS map, in which case these items will be destroyed (not cleared!) and their memory cleaned up automatically when the parent is cleared.
--
ds_list_clear(id);
-Argument | -Type | -Description | -
---|---|---|
id | -DS List ID | -The handle of the data structure to clear. | -
-
N/A
--
if (count == 15) && (!ds_list_empty(command_list))
-
- {
-
- ds_list_clear(command_list);
-
- alarm[0] = game_get_speed(gamespeed_fps);
-
- ai_count = 0;
-
- }
The above code checks a variable to see if it has reached a specific value and if it has it clears the DS list indexed in the variable "command_list", sets an alarm, and resets the variable to 0.
--
-
With this function you can clear all data from the given list data-structure. This does NOT destroy the data-structure (for that you should use ds_list_destroy()) it only wipes all data from it and makes the list empty (zero in size). Note that clearing a list will de-reference any data structures stored in it giving a memory leak, so you would need to go through the list and destroy all data structure items manually before clearing it to prevent this. The only time this is not required is when you have flagged any items in the list as another DS list or as a DS map, in which case these items will be destroyed (not cleared!) and their memory cleaned up automatically when the parent is cleared.
++
ds_list_clear(id);
+Argument | +Type | +Description | +
---|---|---|
id | +DS List | +The handle of the data structure to clear. | +
+
N/A
++
if (count == 15) && (!ds_list_empty(command_list))
+ {
+ ds_list_clear(command_list);
+ alarm[0] = game_get_speed(gamespeed_fps);
+ ai_count = 0;
+ }
The above code checks a variable to see if it has reached a specific value and if it has it clears the DS list indexed in the variable "command_list", sets an alarm, and resets the variable to 0.
++
+
if (!ds_list_empty(main_list))
{
- old_list = ds_list_create();
- ds_list_copy(old_list, main_list);
- ds_list_clear(main_list);
+ old_list = ds_list_create();
+ ds_list_copy(old_list, main_list);
+ ds_list_clear(main_list);
}
The above code will check a DS list to see if it is empty. If it is not empty it is copied into another DS list (which has been created previously) and then the original list is cleared.
diff --git a/Manual/contents/GameMaker_Language/GML_Reference/Data_Structures/DS_Lists/ds_list_delete.htm b/Manual/contents/GameMaker_Language/GML_Reference/Data_Structures/DS_Lists/ds_list_delete.htm index 8177bc34f..b5229050d 100644 --- a/Manual/contents/GameMaker_Language/GML_Reference/Data_Structures/DS_Lists/ds_list_delete.htm +++ b/Manual/contents/GameMaker_Language/GML_Reference/Data_Structures/DS_Lists/ds_list_delete.htm @@ -1,76 +1,73 @@ - + - - -
With this function you can remove the value stored at a specific position within the list.
--
ds_list_delete(id, pos);
-Argument | -Type | -Description | -
---|---|---|
id | -- | The handle of the list to change. | -
pos | -- | Where in the list to delete the value. | -
-
-
-
if (ds_list_size(sc_list) > 10)
-
- {
-
- while (ds_list_size(sc_list) > 10)
-
- {
-
- ds_list_delete(sc_list, 0);
-
- }
-
- }
The above code checks the size of a DS list and if it is larger than ten, it loops through the list removing the top value (position 0) until the list has only 10 entries.
--
-
-
With this function you can remove the value stored at a specific position within the list.
++
ds_list_delete(id, pos);
+Argument | +Type | +Description | +
---|---|---|
id | +DS List | +The handle of the list to change. | +
pos | +Real | +Where in the list to delete the value. | +
+
N/A
++
if (ds_list_size(sc_list) > 10)
+ {
+ while (ds_list_size(sc_list) > 10)
+ {
+ ds_list_delete(sc_list, 0);
+ }
+ }
The above code checks the size of a DS list and if it is larger than ten, it loops through the list removing the top value (position 0) until the list has only 10 entries.
++
+
+
This function will remove the given list data structure from memory, freeing up the resources it was using and removing all values that it contained. This function should always be used when you are finished using the DS list to prevent memory leaks that can slow down and crash your game.
-Destroying a list will de-reference any data structures stored in it giving a memory leak, so you would need to go through the list and destroy all data structure items manually before destroying it to prevent this. The only time this is not required is when you have flagged any items in the list as another DS list or as a DS map, in which case these items will be destroyed and their memory cleaned up automatically as well.
--
ds_list_destroy(id);
-Argument | -Type | -Description | -
---|---|---|
id | -DS List | -The handle of the data structure to remove. | -
-
N/A
--
if (lives == 0)
-
- {
-
- ds_list_destroy(AI_list);
-
- AI_list = -1;
-
- room_goto(rm_Menu);
-
- }
The above code will check the value of the built-in global variable lives and if it is 0, it destroys the DS list indexed in the variable AI_list and then changes rooms.
--
-
This function will remove the given list data structure from memory, freeing up the resources it was using and removing all values that it contained. This function should always be used when you are finished using the DS list to prevent memory leaks that can slow down and crash your game.
+Destroying a list will de-reference any data structures stored in it giving a memory leak, so you would need to go through the list and destroy all data structure items manually before destroying it to prevent this. The only time this is not required is when you have flagged any items in the list as another DS list or as a DS map, in which case these items will be destroyed and their memory cleaned up automatically as well.
++
ds_list_destroy(id);
+Argument | +Type | +Description | +
---|---|---|
id | +DS List | +The handle of the data structure to remove. | +
+
N/A
++
if (lives == 0)
+ {
+ ds_list_destroy(AI_list);
+ AI_list = -1;
+ room_goto(rm_Menu);
+ }
The above code will check the value of the built-in global variable lives and if it is 0, it destroys the DS list indexed in the variable AI_list and then changes rooms.
++
+
With this function you can check the given DS list to see if it is empty (returns true) or not (returns false).
--
ds_list_empty(id);
-Argument | -Type | -Description | -
---|---|---|
id | -DS List id | -The handle of the data structure to check. | -
-
-
if (count == 15( && (!ds_list_empty(command_list))
-
- {
-
- ds_list_clear(command_list);
-
- alarm[0] = game_get_speed(gamespeed_fps);
-
- count = 0;
-
- }
The above code checks a variable to see if it has reached a specific value and if it has it clears the DS list indexed in the variable "command_list", sets an alarm, and resets the variable to 0.
--
-
With this function you can check the given DS list to see if it is empty (returns true) or not (returns false).
++
ds_list_empty(id);
+Argument | +Type | +Description | +
---|---|---|
id | +DS List id | +The handle of the data structure to check. | +
+
+
if (count == 15( && (!ds_list_empty(command_list))
+ {
+ ds_list_clear(command_list);
+ alarm[0] = game_get_speed(gamespeed_fps);
+ count = 0;
+ }
The above code checks a variable to see if it has reached a specific value and if it has it clears the DS list indexed in the variable "command_list", sets an alarm, and resets the variable to 0.
++
+
With this function you can check to see if another DS list is stored at the given position within a DS list. If the given position contains a DS list ID, then the function will return true otherwise it will return false.
-This will only detect lists that were manually marked using the ds_list_mark_as_list function.
--
ds_list_is_list(id, pos);
-Argument | -Type | -Description | -
---|---|---|
id | -DS List | -The handle of the list to check. | -
pos | -Real | -The position within the list to check. | -
-
-
var size = ds_list_size(ships);
-
- for (var i = 0; i < size; i++)
-
- {
-
- if (ds_list_is_list(ships, i))
-
- {
-
- ds_list_destroy(ships[| i]);
-
- }
-
- }
-
- ds_list_destroy(ships);
The above code loops through a DS list and checks to see if any of the entries contain other list IDs. If they do, then these lists are destroyed, and then the main list is destroyed after the loop is finished.
--
-
With this function you can check to see if another DS list is stored at the given position within a DS list. If the given position contains a DS list ID, then the function will return true otherwise it will return false.
+This will only detect lists that were manually marked using the ds_list_mark_as_list function.
++
ds_list_is_list(id, pos);
+Argument | +Type | +Description | +
---|---|---|
id | +DS List | +The handle of the list to check. | +
pos | +Real | +The position within the list to check. | +
+
+
var size = ds_list_size(ships);
+ for (var i = 0; i < size; i++)
+ {
+ if (ds_list_is_list(ships, i))
+ {
+ ds_list_destroy(ships[| i]);
+ }
+ }
+ ds_list_destroy(ships);
The above code loops through a DS list and checks to see if any of the entries contain other list IDs. If they do, then these lists are destroyed, and then the main list is destroyed after the loop is finished.
++
+
With this function you can check to see if a DS map is stored at the given position within a DS list. If the given position contains a DS map ID, then the function will return true otherwise it will return false.
-This will only detect maps that were manually marked using the ds_list_mark_as_map function.
--
ds_list_is_map(id, pos);
-Argument | -Type | -Description | -
---|---|---|
id | -DS List | -The handle of the list to check. | -
pos | -Real | -The position within the list to check. | -
-
-
var size = ds_list_size(ships);
-
- for (var i = 0; i < size; i++)
-
- {
-
- if (ds_list_is_map(ships, i))
-
- {
-
- ds_map_destroy(ships[| i]);
-
- }
-
- }
-
- ds_list_destroy(ships);
The above code loops through a DS list and checks to see if any of the entries contain map IDs. If they do, then these maps are destroyed, and then the main list is destroyed after the loop is finished.
--
-
With this function you can check to see if a DS map is stored at the given position within a DS list. If the given position contains a DS map ID, then the function will return true otherwise it will return false.
+This will only detect maps that were manually marked using the ds_list_mark_as_map function.
++
ds_list_is_map(id, pos);
+Argument | +Type | +Description | +
---|---|---|
id | +DS List | +The handle of the list to check. | +
pos | +Real | +The position within the list to check. | +
+
+
var size = ds_list_size(ships);
+ for (var i = 0; i < size; i++)
+ {
+ if (ds_list_is_map(ships, i))
+ {
+ ds_map_destroy(ships[| i]);
+ }
+ }
+ ds_list_destroy(ships);
The above code loops through a DS list and checks to see if any of the entries contain map IDs. If they do, then these maps are destroyed, and then the main list is destroyed after the loop is finished.
++
+
With this function you can recreate a saved DS list (one that has previously been written as a string using ds_list_write()). You must first create a new DS list to read the string into, and if the DS list already exists and has information stored in it, then this will be cleared before reading. This function is of vital importance when creating save/load mechanisms for your game.
-Note that if the specified DS string was written by the GameMaker: Studio 1.2.x runtime (or older), you should specify the optional argument "legacy", setting it to true as the string format changed after that.
--
ds_list_read(id, str [, legacy]);
-Argument | -Type | -Description | -
---|---|---|
id | -DS List ID | -The handle of the data structure to read into. | -
str | -String | -The string to read from. | -
legacy | -Boolean | -OPTIONAL Can be either true or false or omitted completely. | -
-
N/A
--
list = ds_list_create();
-
- ini_open("save.ini");
-
- var str = ini_read_string("Lists", "0", "");
-
- if (str != "")
-
- {
-
- ds_list_read(list, str);
-
- }
-
- ini_close();
The above code creates a list and stores the index in the variable "list". It then opens an ini file and reads a string from that, checking to make sure that the string is not returned as empty first. This string is then read into the newly created ds_list.
--
-
-
With this function you can recreate a saved DS list (one that has previously been written as a string using ds_list_write()). You must first create a new DS list to read the string into, and if the DS list already exists and has information stored in it, then this will be cleared before reading. This function is of vital importance when creating save/load mechanisms for your game.
+Note that if the specified DS string was written by the GameMaker: Studio 1.2.x runtime (or older), you should specify the optional argument "legacy", setting it to true as the string format changed after that.
++
ds_list_read(id, str [, legacy]);
+Argument | +Type | +Description | +
---|---|---|
id | +DS List | +The handle of the data structure to read into. | +
str | +String | +The string to read from. | +
legacy | +Boolean | +OPTIONAL Can be either true or false or omitted completely. | +
+
N/A
++
list = ds_list_create();
+ ini_open("save.ini");
+ var str = ini_read_string("Lists", "0", "");
+ if (str != "")
+ {
+ ds_list_read(list, str);
+ }
+ ini_close();
The above code creates a list and stores the index in the variable "list". It then opens an ini file and reads a string from that, checking to make sure that the string is not returned as empty first. This string is then read into the newly created ds_list.
++
+
+
With this function you can shuffle a list, which will re-order all the component values into random positions from those in which they were originally added to the list.
--
ds_list_shuffle(id);
-Argument | -Type | -Description | -
---|---|---|
id | -DS List ID | -The handle of the list to shuffle. | -
-
N/A
--
if (restart)
-
- {
-
- ds_list_shuffle(card_list);
-
- }
The above code will shuffle the list indexed in the variable "card_list" if the variable "restart" is flagged as true.
--
-
-
With this function you can shuffle a list, which will re-order all the component values into random positions from those in which they were originally added to the list.
++
ds_list_shuffle(id);
+Argument | +Type | +Description | +
---|---|---|
id | +DS List | +The handle of the list to shuffle. | +
+
N/A
++
if (restart)
+ {
+ ds_list_shuffle(card_list);
+ }
The above code will shuffle the list indexed in the variable "card_list" if the variable "restart" is flagged as true.
++
+
+
This function will return the "size" of the list, ie: the number of items that have been added into it.
--
ds_list_size(id);
-Argument | -Type | -Description | -
---|---|---|
id | -- | The handle of the data structure to check. | -
-
-
-
if (!ds_list_empty(control_list))
-
- {
-
- num = ds_list_size(control_list);
-
- }
The above code checks a DS list to see if it is empty or not, and if it is not, it gets the number of items that it contains and stores the value in a variable.
--
-
-
This function will return the "size" of the list, ie: the number of items that have been added into it.
++
ds_list_size(id);
+Argument | +Type | +Description | +
---|---|---|
id | +DS List | +The handle of the data structure to check. | +
+
+
if (!ds_list_empty(control_list))
+ {
+ num = ds_list_size(control_list);
+ }
The above code checks a DS list to see if it is empty or not, and if it is not, it gets the number of items that it contains and stores the value in a variable.
++
+
+
With this function you can sort all the values within a list, either in ascending or descending order. If the list contains strings, these will be sorted alphabetically, based on the English 26 letter alphabet.
--
ds_list_sort(id, ascend);
-Argument | -Type | -Description | -
---|---|---|
id | -- | The handle of the list to sort. | -
ascend | -- | Whether the values should be ascending (true) or descending (false) order. | -
-
-
-
if (newgame)
-
- {
-
- ds_list_sort(name_list, true);
-
- }
The above code will sort the list indexed in the variable "name_list" if the variable "newgame" is flagged as true.
--
-
-
With this function you can sort all the values within a list, either in ascending or descending order. If the list contains strings, these will be sorted alphabetically, based on the English 26 letter alphabet.
++
ds_list_sort(id, ascend);
+Argument | +Type | +Description | +
---|---|---|
id | +DS List | +The handle of the list to sort. | +
ascend | +Boolean | +Whether the values should be ascending (true) or descending (false) order. | +
+
N/A
++
if (newgame)
+ {
+ ds_list_sort(name_list, true);
+ }
The above code will sort the list indexed in the variable "name_list" if the variable "newgame" is flagged as true.
++
+
+
This function will clear the (previously created) DS map of all key/value pairs, but it will not delete the DS map itself from memory. For that you should use the function ds_map_destroy(). Note that clearing a map will de-reference any data structures stored in the map giving a memory leak, so you would need to go through it and destroy all data structure items manually before clearing the map to prevent this. The only time this is not required is when you have flagged any items in the map as a DS list or as another DS map, in which case these items will be destroyed (not cleared!) and their memory cleaned up automatically when the parent map is cleared.
--
ds_map_clear(id);
-Argument | -Type | -Description | -
---|---|---|
id | -- | The handle of the data structure to clear. | -
-
-
-
if (global.new_game)
-
- {
-
- ds_map_clear(inventory);
-
- }
The above function will check a global variable to see if it is true and, if it is, then the DS map indexed in the instance variable "inventory" will be cleared of all key/value pairs (but it is not destroyed).
--
-
-
This function will clear the (previously created) DS map of all key/value pairs, but it will not delete the DS map itself from memory. For that you should use the function ds_map_destroy(). Note that clearing a map will de-reference any data structures stored in the map giving a memory leak, so you would need to go through it and destroy all data structure items manually before clearing the map to prevent this. The only time this is not required is when you have flagged any items in the map as a DS list or as another DS map, in which case these items will be destroyed (not cleared!) and their memory cleaned up automatically when the parent map is cleared.
++
ds_map_clear(id);
+Argument | +Type | +Description | +
---|---|---|
id | +DS Map | +The handle of the data structure to clear. | +
+
N/A
++
if (global.new_game)
+ {
+ ds_map_clear(inventory);
+ }
The above function will check a global variable to see if it is true and, if it is, then the DS map indexed in the instance variable "inventory" will be cleared of all key/value pairs (but it is not destroyed).
++
+
+
This function will simply return false if the specified (previously created) DS map contains any key/value pairs, or true if it does not.
--
ds_map_empty(id);
-Argument | -Type | -Description | -
---|---|---|
id | -- | The handle of the data structure to check. | -
-
-
-
if (ds_map_empty(inventory))
-
- {
-
- weight = 0;
-
- }
The above code checks to see if the DS map indexed in the variable "inventory" has any key/value pairs and if it does not it sets the variable "weight" to 0.
--
-
-
This function will simply return false if the specified (previously created) DS map contains any key/value pairs, or true if it does not.
++
ds_map_empty(id);
+Argument | +Type | +Description | +
---|---|---|
id | +DS Map | +The handle of the data structure to check. | +
+
+
if (ds_map_empty(inventory))
+ {
+ weight = 0;
+ }
The above code checks to see if the DS map indexed in the variable "inventory" has any key/value pairs and if it does not it sets the variable "weight" to 0.
++
+
+
This function will return true if the specified key exists in the (previously created) DS map , and false if it does not.
--
ds_map_exists(id, key);
-Argument | -Type | -Description | -
---|---|---|
id | -DS Map ID | -The handle of the data structure to check | -
key | -String | -The key to check for | -
-
Boolean
--
if (!ds_map_exists(inventory, "potions"))
-
- {
-
- ds_map_add(inventory, "potions", 1);
-
- }
The above code will check the DS map indexed in the variable "inventory" for the key "potions" and if it doesn't exist it will add it to the map.
--
-
-
This function will return true if the specified key exists in the (previously created) DS map , and false if it does not.
++
ds_map_exists(id, key);
+Argument | +Type | +Description | +
---|---|---|
id | +DS Map | +The handle of the data structure to check | +
key | +String | +The key to check for | +
+
+
if (!ds_map_exists(inventory, "potions"))
+ {
+ ds_map_add(inventory, "potions", 1);
+ }
The above code will check the DS map indexed in the variable "inventory" for the key "potions" and if it doesn't exist it will add it to the map.
++
+
+
This function returns the first key stored in the DS map. This is not the first key in the order you added them! DS maps are not stored in a linear form, for that use DS list, so all this does is find the first key as stored by the computer. This can be useful if your have to iterate through the DS map looking for something, but should be avoided if possible as it can be slow.
-Note that this function will return undefined if the given DS map is empty.
--
ds_map_find_first(id);
-Argument | -Type | -Description | -
---|---|---|
id | -- | The handle of the map to use. | -
-
Variable or undefined
--
var size = ds_map_size(inventory) ;
-
- var key = ds_map_find_first(inventory);
-
- for (var i = 0; i < size; i++;)
-
- {
-
- if (key != "gold")
-
- {
-
- key = ds_map_find_next(inventory, key);
-
- }
-
- else break;
-
- }
The above code creates some temporary variables and then gets the DS map size and finds the first key as stored by the computer in the map. It then uses a for loop to iterate through the DS map looking for the key value "gold". If it finds it, it breaks out the loop.
--
-
-
This function returns the first key stored in the DS map. This is not the first key in the order you added them! DS maps are not stored in a linear form, for that use DS list, so all this does is find the first key as stored by the computer. This can be useful if your have to iterate through the DS map looking for something, but should be avoided if possible as it can be slow.
+Note that this function will return undefined if the given DS map is empty.
++
ds_map_find_first(id);
+Argument | +Type | +Description | +
---|---|---|
id | +DS Map | +The handle of the map to use. | +
+
+
var size = ds_map_size(inventory) ;
+ var key = ds_map_find_first(inventory);
+ for (var i = 0; i < size; i++;)
+ {
+ if (key != "gold")
+ {
+ key = ds_map_find_next(inventory, key);
+ }
+ else break;
+ }
The above code creates some temporary variables and then gets the DS map size and finds the first key as stored by the computer in the map. It then uses a for loop to iterate through the DS map looking for the key value "gold". If it finds it, it breaks out the loop.
++
+
+
This function returns the last key stored in the DS map. This is not the last key in the order that you have added them! DS maps are not stored in a linear form, for that use DS lists, so all this does is find the last key as stored by the computer. This can be useful if your have to iterate through the DS map looking for something, but should be avoided if possible as it can be slow.
-Note that this function will return undefined if the given DS map is empty.
--
ds_map_find_last(id);
-Argument | -Type | -Description | -
---|---|---|
id | -- | The handle of the map to use. | -
-
Variable or undefined
--
var size = ds_map_size(inventory);
-
- var key = ds_map_find_last(inventory);
-
- for (var i = size; i > 0; i--;)
-
- {
-
- if (key != "gold")
-
- {
-
- key = ds_map_find_previous(inventory, key);
-
- }
-
- else break;
-
- }
The above code creates some temporary variables and then gets the DS map size and finds the last key as stored by the computer in the map. It then uses a for loop to iterate back through the DS map looking for the key value "gold". If it finds it, it breaks out the loop.
--
-
-
This function returns the last key stored in the DS map. This is not the last key in the order that you have added them! DS maps are not stored in a linear form, for that use DS lists, so all this does is find the last key as stored by the computer. This can be useful if your have to iterate through the DS map looking for something, but should be avoided if possible as it can be slow.
+Note that this function will return undefined if the given DS map is empty.
++
ds_map_find_last(id);
+Argument | +Type | +Description | +
---|---|---|
id | +DS Map | +The handle of the map to use. | +
+
+
var size = ds_map_size(inventory);
+ var key = ds_map_find_last(inventory);
+ for (var i = size; i > 0; i--;)
+ {
+ if (key != "gold")
+ {
+ key = ds_map_find_previous(inventory, key);
+ }
+ else break;
+ }
The above code creates some temporary variables and then gets the DS map size and finds the last key as stored by the computer in the map. It then uses a for loop to iterate back through the DS map looking for the key value "gold". If it finds it, it breaks out the loop.
++
+
+
This function returns the next key stored in the DS map after the one specified in the function. This can be useful if your have to iterate through the DS map looking for something, but should be avoided if possible as it can be slow. If no such key exists then the function will return undefined. You should always check this using the is_undefined() function.
--
ds_map_find_next(id, key);
-Argument | -Type | -Description | -
---|---|---|
id | -- | The handle of the map to use. | -
key | -- | The key to find the next one to. | -
-
Variable or undefined
--
var size = ds_map_size(inventory);
-
- var key = ds_map_find_first(inventory);
-
- for (var i = 0; i < size; i++;)
-
- {
-
- if (key != "gold")
-
- {
-
- key = ds_map_find_next(inventory, key);
-
- }
-
- else break;
-
- }
The above code creates some temporary variables and then gets the DS map size and finds the first key as stored by the computer in the map. It then uses a for loop to iterate through the DS map looking for the key value "gold". If it finds it, it breaks out the loop.
--
-
-
This function returns the next key stored in the DS map after the one specified in the function. This can be useful if your have to iterate through the DS map looking for something, but should be avoided if possible as it can be slow. If no such key exists then the function will return undefined. You should always check this using the is_undefined() function.
++
ds_map_find_next(id, key);
+Argument | +Type | +Description | +
---|---|---|
id | +DS Map | +The handle of the map to use. | +
key | +String | +The key to find the next one to. | +
+
+
var size = ds_map_size(inventory);
+ var key = ds_map_find_first(inventory);
+ for (var i = 0; i < size; i++;)
+ {
+ if (key != "gold")
+ {
+ key = ds_map_find_next(inventory, key);
+ }
+ else break;
+ }
The above code creates some temporary variables and then gets the DS map size and finds the first key as stored by the computer in the map. It then uses a for loop to iterate through the DS map looking for the key value "gold". If it finds it, it breaks out the loop.
++
+
+
This function returns the previous key stored in the DS map before the one specified in the function. This can be useful if your have to iterate through the DS map looking for something, but should be avoided if possible as it can be slow. If no such key exists then the function will return undefined. You should always check this using the is_undefined() function.
--
ds_map_find_previous(id, key);
-Argument | -Type | -Description | -
---|---|---|
id | -- | The handle of the map to use. | -
key | -- | The key to find the previous one to. | -
-
Variable or undefined
--
var size = ds_map_size(inventory) - 1;
-
- var key = ds_map_find_last(inventory);
-
- for (var i = size; i > 0; i--;)
-
- {
-
- if (key != "gold")
-
- {
-
- key = ds_map_find_previous(inventory, key);
-
- }
-
- else break;
-
- }
The above code creates some temporary variables and then gets the ds_map size and finds the last key as stored by the computer in the map. It then uses a for loop to iterate back through the ds_map looking for the key value "gold". If it finds it, it breaks out the loop.
--
-
-
This function returns the previous key stored in the DS map before the one specified in the function. This can be useful if your have to iterate through the DS map looking for something, but should be avoided if possible as it can be slow. If no such key exists then the function will return undefined. You should always check this using the is_undefined() function.
++
ds_map_find_previous(id, key);
+Argument | +Type | +Description | +
---|---|---|
id | +DS Map | +The handle of the map to use. | +
key | +String | +The key to find the previous one to. | +
+
+
var size = ds_map_size(inventory) - 1;
+ var key = ds_map_find_last(inventory);
+ for (var i = size; i > 0; i--;)
+ {
+ if (key != "gold")
+ {
+ key = ds_map_find_previous(inventory, key);
+ }
+ else break;
+ }
The above code creates some temporary variables and then gets the ds_map size and finds the last key as stored by the computer in the map. It then uses a for loop to iterate back through the ds_map looking for the key value "gold". If it finds it, it breaks out the loop.
++
+
+
With this function you can check to see if a DS list is stored in the given map key. If the given key contains a DS list ID, then the function will return true otherwise it will return false.
-This will only detect lists that were added using the ds_map_add_list function.
--
ds_map_is_list(id, key)
-Argument | -Type | -Description | -
---|---|---|
id | -DS Map | -The handle of the map to use. | -
key | -String | -The key to check. | -
-
-
var size = ds_map_size(inventory);
-
- var key = ds_map_find_first(inventory);
-
- for (var i = 0; i < size; i++)
-
- {
-
- if (ds_map_is_list(inventory, key))
-
- {
-
- ds_list_destroy(inventory[? key]);
-
- }
-
- key = ds_map_find_next(inventory);
-
- }
-
- ds_map_destroy(inventory);
The above code loops through a DS map and checks to see if any of the keys in it are for a DS list. If they are, then the DS list is destroyed, and the at the end of the loop the DS map is destroyed too.
--
-
With this function you can check to see if a DS list is stored in the given map key. If the given key contains a DS list ID, then the function will return true otherwise it will return false.
+This will only detect lists that were added using the ds_map_add_list function.
++
ds_map_is_list(id, key)
+Argument | +Type | +Description | +
---|---|---|
id | +DS Map | +The handle of the map to use. | +
key | +String | +The key to check. | +
+
+
var size = ds_map_size(inventory);
+ var key = ds_map_find_first(inventory);
+ for (var i = 0; i < size; i++)
+ {
+ if (ds_map_is_list(inventory, key))
+ {
+ ds_list_destroy(inventory[? key]);
+ }
+
+ key = ds_map_find_next(inventory);
+ }
+
+ ds_map_destroy(inventory);
+
The above code loops through a DS map and checks to see if any of the keys in it are for a DS list. If they are, then the DS list is destroyed, and the at the end of the loop the DS map is destroyed too.
++
+
With this function you can check to see if a DS map is stored in the given map key. If the given key contains a DS map ID, then the function will return true otherwise it will return false.
-This will only detect maps that were added using the ds_map_add_map function.
--
ds_map_is_map(id, key)
-Argument | -Type | -Description | -
---|---|---|
id | -DS Map | -The handle of the map to use. | -
key | -String | -The key to replace. | -
-
-
var size = ds_map_size(inventory);
-
- var key = ds_map_find_first(inventory);
-
- for (var i = 0; i < size; i++)
-
- {
-
- if (ds_map_is_map(inventory, key))
-
- {
-
- ds_map_destroy(inventory[? key]);
-
- }
-
- key = ds_map_find_next(inventory);
-
- }
-
- ds_map_destroy(inventory);
The above code loops through a DS map and checks to see if any of the keys within it are for other DS maps. If they are, then the stored DS map is destroyed, and the at the end of the loop the main DS map is destroyed too.
--
-
With this function you can check to see if a DS map is stored in the given map key. If the given key contains a DS map ID, then the function will return true otherwise it will return false.
+This will only detect maps that were added using the ds_map_add_map function.
++
ds_map_is_map(id, key)
+Argument | +Type | +Description | +
---|---|---|
id | +DS Map | +The handle of the map to use. | +
key | +String | +The key to replace. | +
+
+
var size = ds_map_size(inventory);
+ var key = ds_map_find_first(inventory);
+ for (var i = 0; i < size; i++)
+ {
+ if (ds_map_is_map(inventory, key))
+ {
+ ds_map_destroy(inventory[? key]);
+ }
+ key = ds_map_find_next(inventory);
+ }
+ ds_map_destroy(inventory);
The above code loops through a DS map and checks to see if any of the keys within it are for other DS maps. If they are, then the stored DS map is destroyed, and the at the end of the loop the main DS map is destroyed too.
++
+
This function will take a string that has previously been created by the function ds_map_write() and then read it into a previously created DS map. If the map that the string is being read into contains any key/value pairs, these will be cleared first before the saved map is re-constructed.
-Note that if the specified DS string was written by the GameMaker: Studio 1.2.x runtime (or older), you should specify the optional argument "legacy", setting it to true as the string format changed after that.
--
ds_map_read(id, str, [legacy]);
-Argument | -Type | -Description | -
---|---|---|
id | -DS Map ID | -The handle of the data structure to read the string into | -
str | -String | -The string to read | -
legacy | -Boolean | -OPTIONAL Can be either true or false or omitted completely. | -
-
N/A
--
inventory = ds_map_create();
-
- ini_open("map.ini");
-
- var t_string = ini_read_string("Saved", "0", "");
-
- if (t_string != "")
-
- {
-
- ds_map_read(inventory, t_string);
-
- }
-
- ini_close();
The above code creates a new DS map and stores its id index in the variable "inventory". It then opens an ini file and reads a string from that file into the temporary variable "t_string". Finally, it checks to make sure that the string is valid (not the default ini value of "") and if it is it then reads the string into the newly created DS map before closing the ini again.
--
-
-
This function will take a string that has previously been created by the function ds_map_write() and then read it into a previously created DS map. If the map that the string is being read into contains any key/value pairs, these will be cleared first before the saved map is re-constructed.
+Note that if the specified DS string was written by the GameMaker: Studio 1.2.x runtime (or older), you should specify the optional argument "legacy", setting it to true as the string format changed after that.
++
ds_map_read(id, str, [legacy]);
+Argument | +Type | +Description | +
---|---|---|
id | +DS Map | +The handle of the data structure to read the string into | +
str | +String | +The string to read | +
legacy | +Boolean | +OPTIONAL Can be either true or false or omitted completely. | +
+
N/A
++
inventory = ds_map_create();
+ ini_open("map.ini");
+ var t_string = ini_read_string("Saved", "0", "");
+ if (t_string != "")
+ {
+ ds_map_read(inventory, t_string);
+ }
+ ini_close();
The above code creates a new DS map and stores its id index in the variable "inventory". It then opens an ini file and reads a string from that file into the temporary variable "t_string". Finally, it checks to make sure that the string is valid (not the default ini value of "") and if it is it then reads the string into the newly created DS map before closing the ini again.
++
+
+
With this function you can find how many key/values pairs the (previously created) DS map contains.
--
ds_map_size(id);
-Argument | -Type | -Description | -
---|---|---|
id | -- | The handle of the data structure to check. | -
-
-
-
if (ds_map_size(inventory) > 49)
-
- {
-
- full = true;
-
- }
The above code will check the size of the DS map (ie: number of key/value pairs) and if it is greater than 49 it sets the variable "full" to true.
--
-
-
With this function you can find how many key/values pairs the (previously created) DS map contains.
++
ds_map_size(id);
+Argument | +Type | +Description | +
---|---|---|
id | +