F
FriendlyCosmonaut
Guest
GM Version: GameMaker Studio 2
Download: Example File
Links: Asset on Marketplace
Summary:
In GMS1, "depth = -y" served as a simple, fast, dependable way to sort depth dynamically, especially for beginners. In GMS2, with the introduction of layers, it's easy to run into some trouble with this method. Therefore, I've tried to come up with a relatively simple method that I hope won't be too tricky for beginners.
My system doesn't actually rely on "depth" at all. Instead, we take advantage of the draw order of instances. We require two objects and one script: (1) a master draw object, (2) a parent object whose children will be every object whose depth you want to sort. The script adds these objects to the system. This is the gist of it:
Tutorial:
Download: Example File
Links: Asset on Marketplace
Summary:
In GMS1, "depth = -y" served as a simple, fast, dependable way to sort depth dynamically, especially for beginners. In GMS2, with the introduction of layers, it's easy to run into some trouble with this method. Therefore, I've tried to come up with a relatively simple method that I hope won't be too tricky for beginners.
My system doesn't actually rely on "depth" at all. Instead, we take advantage of the draw order of instances. We require two objects and one script: (1) a master draw object, (2) a parent object whose children will be every object whose depth you want to sort. The script adds these objects to the system. This is the gist of it:
- We set up a ds_grid with two columns: one for instances' IDs, and the other for instances' Y values.
- All the object instances add themselves and their Y position to this grid via a script. We also disable instances' default draw event so that they are no longer drawing themselves.
- A master "draw" object then sorts the grid by the "Y value" column, so that instances with a lower Y (which are up the top of the room) come first in the grid.
- The master draw object then loops through the grid and draws all the objects in order. That way, instances with lower Y values are drawn first, behind objects that have higher Y values.
Tutorial: