A lot of 2D games and typically 2D RPGs achieve the illusion of depth when players and characters move "behind" and "in front" of objects. The contents of this package allow you to add such a system to your game in Game Maker Studio 2.
HOW IT WORKS:
A ds_grid is setup with two columns: one for instances' IDs, and the other for instances' Y values.
We make all the instances we want part of the depth system a child of a "depth parent" object. We create an "empty draw" event to disable the instances' default draw event so that they are no longer drawing themselves.
A master "draw" object adds all the instances and their corresponding Y value to the grid. It 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.
HOW TO USE THE SYSTEM:
There are two objects: obj_draw and obj_parent_depth. Add these to your project.
Add obj_draw to your room in the same layer you keep your object instances. If you have multiple Instances layers, place it at the layer with the lowest depth.
Make all objects you want to be included in the depth system a child of the parent object, obj_parent_depth.
CODE IT YOURSELF:
This video provides a tutorial on how you can code this system from scratch.
This video provides a tutorial on how to optimise the system, make it much simpler and faster.
Version 1.0.1. Published May 17, 2017
You can only review assets you've bought.
Smart, Fun and Educational
Friendly Cosmonaut is one of my favorite GM2 tutorial creators on YouTube :) She makes working with gml programming a million times more understandable & fun.
Thanks for making this source code available in Marketplace and all of your wonderful tutorials :)