Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add some helper methods for changing rendering order #6782

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
124 changes: 124 additions & 0 deletions src/gameobjects/components/Depth.js
Expand Up @@ -12,6 +12,8 @@
* @since 3.0.0
*/

var ArrayUtils = require('../../utils/array');

var Depth = {

/**
Expand Down Expand Up @@ -83,6 +85,128 @@ var Depth = {

this.depth = value;

return this;
},

/**
* Bring this Game Object to top of display list.
*
* @method Phaser.GameObjects.Components.Depth#bringMeToTop
* @since 3.80.2
* @return {this} This Game Object instance.
*/
bringMeToTop: function()
{
var list;
if (this.parentContainer)
{
list = this.parentContainer.list;
}
else if (this.displayList)
{
list = this.displayList.list;
}

if (!list)
{
return this;
}

ArrayUtils.BringToTop(list, this);

return this;
},

/**
* Send this Game Object to bottom of display list.
*
* @method Phaser.GameObjects.Components.Depth#sendMeToBack
* @since 3.80.2
* @return {this} This Game Object instance.
*/
sendMeToBack: function()
{
var list;
if (this.parentContainer)
{
list = this.parentContainer.list;
}
else if (this.displayList)
{
list = this.displayList.list;
}

if (!list)
{
return this;
}

ArrayUtils.SendToBack(list, this);

return this;
},

/**
* Move this Game Object below another Game Object.
*
* @method Phaser.GameObjects.Components.Depth#moveMyDepthBelow
* @since 3.80.2
*
* @param {Phaser.GameObjects.GameObject} gameObject - Move this Game Object below this Game Object.
*
* @return {this} This Game Object instance.
*/
moveMyDepthBelow: function(gameObject)
{
var list;
if (this.parentContainer)
{
list = this.parentContainer.list;
}
else if (this.displayList)
{
list = this.displayList.list;
}

if (!list)
{
return this;
}

ArrayUtils.MoveBelow(list, this, gameObject);

return this;
},

/**
* Move this Game Object above another Game Object.
*
* @method Phaser.GameObjects.Components.Depth#moveMyDepthAbove
* @since 3.80.2
*
* @param {Phaser.GameObjects.GameObject} gameObject - Move this Game Object above this Game Object.
*
* @return {this} This Game Object instance.
*/
moveMyDepthAbove: function(gameObject)
{
var list;
if (this.parentContainer)
{
list = this.parentContainer.list;
}
else if (this.displayList)
{
list = this.displayList.list;
}

if (!list)
{
return this;
}

ArrayUtils.MoveAbove(list, this, gameObject);

return this;
}

Expand Down