Jack of all Errors
- Dec 17, 2012
- Reaction score
- First Language
- Primarily Uses
Z-indexesZ-indexes in RPG Maker MV is vastly different from those in any maker before it. In fact, there technically isn’t a Z index. Object height in MV is based on when the object was added to the drawing layer. In the past, creating a sprite and giving it a bitmap was enough to make it visible on the screen; In MV, you need to create the sprite, add the bitmap, and then give it to the scene to draw it.
There are a couple ways to add things to the list of objects to draw, addChild, and addWindow.
How object depth works
RPG Maker MV uses the Pixi.js v2 library to handle all rendering of the game on the screen. Pixi.js itself does not support z-indexes, which is why MV does not have them. Instead, object depth depends on what order objects are added to a drawable surface.
The Scene_Base class inherits from the PIXI.Stage class, which is essentially just a class that holds objects to be drawn on screen. These objects are drawn in the order they are added into the list, meaning that objects will drawn above those added before them.
addChild / addChildAt
addChild and addChildAt are Pixi’s ways to add an object to the list. addChild will internally just call addChildAt with the index being the next spot in the array.
addChild takes one argument, the object to add to the list.
addChildAt takes two arguments, the object to add, and the location to put it. Using this, you can effectively choose the Z-index of your object, but only when first adding it.
addWindow is a function implemented by MV itself. It adds objects to a specific layer that each scene creates, the Window Layer. However, sometimes this is not the desired behavior. An unwanted occurrence of putting multiple things on the same layer is that if they overlap, they overwrite each other. You can easily see this by using the default windowskin and placing two windows on top of each other. That's why addChild is recommended if you know there is a chance objects will overlap. If this won't happen, addWindow will suite your needs perfectly.
“But I need my z-indexes! There has to be some way to implement them!” - A lot of people, probably.
Well, there is. You’d need to implement this in some way.
EDIT: removed some stray tags.
EDIT: At some point the forums decided bold text wasn't cool.
Last edited by a moderator: