Skip to content

Commit 6ef9e30

Browse files
committed
Added z property to remaining game objects and updated TypeScript defs.
1 parent 5379717 commit 6ef9e30

6 files changed

Lines changed: 40 additions & 16 deletions

File tree

build/phaser.d.ts

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1885,6 +1885,7 @@ declare module Phaser {
18851885
postUpdate(): void;
18861886
preUpdate(): void;
18871887
update(): void;
1888+
z: nummber;
18881889
}
18891890

18901891
class Group extends PIXI.DisplayObjectContainer {
@@ -1934,11 +1935,13 @@ declare module Phaser {
19341935
forEachDead(callback: Function, callbackContext: Object): void;
19351936
forEachExists(callback: Function, callbackContext: Object): void;
19361937
getAt(index: number): any;
1938+
getBottom(): any;
19371939
getFirstAlive(): any;
19381940
getFirstDead(): any;
19391941
getFirstExists(state: boolean): any;
19401942
getIndex(child: any): number;
19411943
getRandom(startIndex: number, length: number): any;
1944+
getTop(): any;
19421945
iterate(key: string, value: any, returnType: number, callback?: Function, callbackContext?: Object): any;
19431946
multiplyAll(property: string, amount: number, checkAlive: boolean, checkVisible: boolean): void;
19441947
next(): void;
@@ -1957,6 +1960,8 @@ declare module Phaser {
19571960
subAll(property: string, amount: number, checkAlive: boolean, checkVisible: boolean): void;
19581961
swap(child1: any, child2: any): boolean;
19591962
update(): void;
1963+
updateZ(): void;
1964+
z: nummber;
19601965
}
19611966

19621967
class Image extends PIXI.Sprite {
@@ -2002,6 +2007,7 @@ declare module Phaser {
20022007
reset(x: number, y: number): Phaser.Image;
20032008
revive(): Phaser.Image;
20042009
update(): void;
2010+
z: nummber;
20052011
}
20062012

20072013
class Input {
@@ -3312,6 +3318,7 @@ declare module Phaser {
33123318
reset(x: number, y: number, health?: number): Phaser.Sprite;
33133319
revive(health?: number): Phaser.Sprite;
33143320
update(): void;
3321+
z: nummber;
33153322
}
33163323

33173324
class SpriteBatch extends Phaser.Group {
@@ -3509,6 +3516,7 @@ declare module Phaser {
35093516
setShadow(x?: number, y?: number, color?: Object, blur?: number): void;
35103517
setStyle(style?: { font?: string; fill?: Object; align?: string; stroke?: string; strokeThickness?: number; wordWrap?: boolean; wordWrapWidth?: number; shadowOffsetX?: number; shadowOffsetY?: number; shadowColor?: string; shadowBlur?: number; }): void;
35113518
update(): void;
3519+
z: nummber;
35123520
}
35133521

35143522
class Tile {
@@ -3682,6 +3690,7 @@ declare module Phaser {
36823690
renderDebug(): void;
36833691
resizeWorld(): void;
36843692
updateMax(): void;
3693+
z: nummber;
36853694
}
36863695

36873696
class TilemapParser {
@@ -3745,6 +3754,7 @@ declare module Phaser {
37453754
preUpdate(): void;
37463755
stopScroll(): void;
37473756
update(): void;
3757+
z: nummber;
37483758
}
37493759

37503760
class Time {

examples/groups/depth sort.js

Lines changed: 13 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -29,13 +29,13 @@ function create() {
2929
// This group will hold the main player + all the tree sprites to depth sort against
3030
group = game.add.group();
3131

32-
// Create some trees, each in a unique location (otherwise we'll get sort flicker)
32+
// Create some trees, each in a unique location
3333
for (var i = 0; i < 200; i++)
3434
{
3535
createUniqueLocation();
3636
}
3737

38-
sprite = group.create(300, 32, 'phaser');
38+
sprite = group.create(300, 28, 'phaser');
3939

4040
group.sort();
4141

@@ -46,20 +46,19 @@ function create() {
4646

4747
function createUniqueLocation() {
4848

49-
var x = game.math.snapTo(game.world.randomX, 32) / 32;
50-
var y = game.math.snapTo(game.world.randomY, 32) / 32;
51-
y--;
49+
do {
50+
var x = game.math.snapTo(game.world.randomX, 32) / 32;
51+
var y = game.math.snapTo(game.world.randomY, 32) / 32;
5252

53-
var idx = (y * 19) + x;
53+
if (y > 17)
54+
{
55+
y = 17;
56+
}
5457

55-
while (locs.indexOf(idx) !== -1)
56-
{
57-
x = game.math.snapTo(game.world.randomX, 32) / 32;
58-
y = game.math.snapTo(game.world.randomY, 32) / 32;
59-
y--;
60-
idx = (y * 19) + x;
58+
var idx = (y * 17) + x;
6159
}
62-
60+
while (locs.indexOf(idx) !== -1)
61+
6362
locs.push(idx);
6463

6564
group.create(x * 32, y * 32, 'trees', game.rnd.integerInRange(0, 7));
@@ -92,8 +91,6 @@ function update() {
9291

9392
function render() {
9493

95-
// game.debug.text(sprite.y, 32, 32);
96-
// game.debug.text(group.getIndex(sprite), 32, 64);
97-
// game.debug.text(sprite.z, 32, 64);
94+
game.debug.text('Sprite z-depth: ' + sprite.z, 10, 20);
9895

9996
}

src/core/Group.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1072,6 +1072,8 @@ Phaser.Group.prototype.sort = function (index, order) {
10721072
this.children.sort(this.descendingSortHandler.bind(this));
10731073
}
10741074

1075+
this.updateZ();
1076+
10751077
}
10761078

10771079
/**

src/gameobjects/BitmapText.js

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,11 @@ Phaser.BitmapText = function (game, x, y, font, text, size) {
5454
*/
5555
this.type = Phaser.BITMAPTEXT;
5656

57+
/**
58+
* @property {number} z - The z-depth value of this object within its Group (remember the World is a Group as well). No two objects in a Group can have the same z value.
59+
*/
60+
this.z = 0;
61+
5762
/**
5863
* @property {Phaser.Point} world - The world coordinates of this Sprite. This differs from the x/y coordinates which are relative to the Sprites container.
5964
*/

src/gameobjects/Graphics.js

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,11 @@ Phaser.Graphics = function (game, x, y) {
4242
*/
4343
this.type = Phaser.GRAPHICS;
4444

45+
/**
46+
* @property {number} z - The z-depth value of this object within its Group (remember the World is a Group as well). No two objects in a Group can have the same z value.
47+
*/
48+
this.z = 0;
49+
4550
/**
4651
* @property {Phaser.Point} world - The world coordinates of this Sprite. This differs from the x/y coordinates which are relative to the Sprites container.
4752
*/

src/gameobjects/Text.js

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,11 @@ Phaser.Text = function (game, x, y, text, style) {
4848
*/
4949
this.type = Phaser.TEXT;
5050

51+
/**
52+
* @property {number} z - The z-depth value of this object within its Group (remember the World is a Group as well). No two objects in a Group can have the same z value.
53+
*/
54+
this.z = 0;
55+
5156
/**
5257
* @property {Phaser.Point} world - The world coordinates of this Sprite. This differs from the x/y coordinates which are relative to the Sprites container.
5358
*/

0 commit comments

Comments
 (0)