Skip to content

Commit 90b1946

Browse files
committed
Input Handler mostly restored
1 parent 78598ae commit 90b1946

7 files changed

Lines changed: 831 additions & 40 deletions

File tree

examples/linkedlist1.php

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -30,33 +30,33 @@ function preload() {
3030

3131
function create() {
3232

33-
a = game.add.sprite(game.world.randomX, game.world.randomY, 'ship');
33+
a = game.add.sprite(100, 100, 'ship');
3434
a.name = 's1';
35-
b = game.add.sprite(game.world.randomX, game.world.randomY, 'ship');
35+
b = game.add.sprite(130, 100, 'ship');
3636
b.name = 's2';
37-
c = game.add.sprite(game.world.randomX, game.world.randomY, 'ship');
37+
c = game.add.sprite(160, 100, 'ship');
3838
c.name = 's3';
39-
d = game.add.sprite(game.world.randomX, game.world.randomY, 'alien');
39+
d = game.add.sprite(190, 100, 'alien');
4040
d.name = 'a1';
41-
e = game.add.sprite(game.world.randomX, game.world.randomY, 'alien');
41+
e = game.add.sprite(220, 100, 'alien');
4242
e.name = 'a2';
43-
f = game.add.sprite(game.world.randomX, game.world.randomY, 'alien');
43+
f = game.add.sprite(250, 100, 'alien');
4444
f.name = 'a3';
4545

4646
list = new Phaser.LinkedList();
4747

4848
list.add(a.input);
49-
list.add(b.input);
50-
list.add(c.input);
51-
list.add(d.input);
52-
list.add(e.input);
53-
list.add(f.input);
49+
// list.add(b.input);
50+
// list.add(c.input);
51+
// list.add(d.input);
52+
// list.add(e.input);
53+
// list.add(f.input);
5454

5555
list.dump();
5656

57-
list.remove(d.input);
57+
// list.remove(d.input);
5858

59-
list.dump();
59+
// list.dump();
6060

6161
}
6262

src/core/LinkedList.js

Lines changed: 23 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,8 @@ Phaser.LinkedList = function () {
33

44
Phaser.LinkedList.prototype = {
55

6-
_iNext: null,
7-
_iPrev: null,
6+
next: null,
7+
prev: null,
88
first: null,
99
last: null,
1010
sprite: { name: 'HD' },
@@ -16,15 +16,15 @@ Phaser.LinkedList.prototype = {
1616
{
1717
this.first = child;
1818
this.last = child;
19-
this._iNext = child;
20-
child._iPrev = this;
19+
this.next = child;
20+
child.prev = this;
2121
return;
2222
}
2323

2424
// Get gets appended to the end of the list, regardless of anything, and it won't have any children of its own (non-nested list)
25-
this.last._iNext = child;
25+
this.last.next = child;
2626

27-
child._iPrev = this.last;
27+
child.prev = this.last;
2828

2929
this.last = child;
3030

@@ -43,22 +43,22 @@ Phaser.LinkedList.prototype = {
4343
{
4444
this.first = null;
4545
this.last = null;
46-
this._iNext = null;
47-
child._iNext = null;
48-
child._iPrev = null;
46+
this.next = null;
47+
child.next = null;
48+
child.prev = null;
4949
return;
5050
}
5151

52-
var childPrev = child._iPrev;
52+
var childPrev = child.prev;
5353

5454
// Tail node?
55-
if (child._iNext)
55+
if (child.next)
5656
{
5757
// Has another node after it?
58-
child._iNext._iPrev = child._iPrev;
58+
child.next.prev = child.prev;
5959
}
6060

61-
childPrev._iNext = child._iNext;
61+
childPrev.next = child.next;
6262

6363
},
6464

@@ -72,14 +72,14 @@ Phaser.LinkedList.prototype = {
7272
var nameFirst = '-';
7373
var nameLast = '-';
7474

75-
if (this._iNext)
75+
if (this.next)
7676
{
77-
nameNext = this._iNext.sprite.name;
77+
nameNext = this.next.sprite.name;
7878
}
7979

80-
if (this._iPrev)
80+
if (this.prev)
8181
{
82-
namePrev = this._iPrev.sprite.name;
82+
namePrev = this.prev.sprite.name;
8383
}
8484

8585
if (this.first)
@@ -116,7 +116,7 @@ Phaser.LinkedList.prototype = {
116116

117117
var entity = this;
118118

119-
var testObject = entity.last._iNext;
119+
var testObject = entity.last.next;
120120
entity = entity.first;
121121

122122
do
@@ -127,14 +127,14 @@ Phaser.LinkedList.prototype = {
127127
var nameFirst = '-';
128128
var nameLast = '-';
129129

130-
if (entity._iNext)
130+
if (entity.next)
131131
{
132-
nameNext = entity._iNext.sprite.name;
132+
nameNext = entity.next.sprite.name;
133133
}
134134

135-
if (entity._iPrev)
135+
if (entity.prev)
136136
{
137-
namePrev = entity._iPrev.sprite.name;
137+
namePrev = entity.prev.sprite.name;
138138
}
139139

140140
if (entity.first)
@@ -169,7 +169,7 @@ Phaser.LinkedList.prototype = {
169169

170170
console.log(name + '\t\t\t|\t\t' + nameNext + '\t\t\t|\t\t' + namePrev + '\t\t\t|\t\t' + nameFirst + '\t\t\t|\t\t' + nameLast);
171171

172-
entity = entity._iNext;
172+
entity = entity.next;
173173

174174
}
175175
while(entity != testObject)

src/core/World.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,8 @@ Phaser.World.prototype = {
1818
bounds: null,
1919
camera: null,
2020

21+
currentRenderOrderID: 0,
22+
2123
boot: function () {
2224

2325
this.camera = new Phaser.Camera(this.game, 0, 0, 0, this.game.width, this.game.height);
@@ -56,6 +58,8 @@ Phaser.World.prototype = {
5658

5759
this.camera.update();
5860

61+
this.currentRenderOrderID = 0;
62+
5963
if (this._stage.first._iNext)
6064
{
6165
var currentNode = this._stage.first._iNext;

src/gameobjects/Sprite.js

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,11 @@ Phaser.Sprite = function (game, x, y, key, frame) {
1414
this.alive = true;
1515

1616
this.group = null;
17+
1718
this.name = '';
1819

20+
this.renderOrderID = -1;
21+
1922
if (key)
2023
{
2124
PIXI.Sprite.call(this, PIXI.TextureCache[key]);
@@ -149,6 +152,7 @@ Phaser.Sprite.prototype.update = function() {
149152

150153
if (!this.exists)
151154
{
155+
this.renderOrderID = -1;
152156
return;
153157
}
154158

@@ -173,6 +177,8 @@ Phaser.Sprite.prototype.update = function() {
173177

174178
if (this.visible)
175179
{
180+
this.renderOrderID = this.game.world.currentRenderOrderID++;
181+
176182
// |a c tx|
177183
// |b d ty|
178184
// |0 0 1|
@@ -256,6 +262,11 @@ Phaser.Sprite.prototype.update = function() {
256262

257263
this.body.update();
258264

265+
if (this.input.enabled)
266+
{
267+
this.input.update();
268+
}
269+
259270
}
260271

261272
Phaser.Sprite.prototype.postUpdate = function() {
@@ -374,3 +385,38 @@ Object.defineProperty(Phaser.Sprite.prototype, "inCamera", {
374385
}
375386

376387
});
388+
389+
Object.defineProperty(Phaser.Sprite.prototype, "inputEnabled", {
390+
391+
/**
392+
* Get the input enabled state of this Sprite.
393+
*/
394+
get: function () {
395+
396+
return (this.input.enabled);
397+
398+
},
399+
400+
/**
401+
* Set the ability for this sprite to receive input events.
402+
*/
403+
set: function (value) {
404+
405+
if (value)
406+
{
407+
if (this.input.enabled == false)
408+
{
409+
this.input.start();
410+
}
411+
}
412+
else
413+
{
414+
if (this.input.enabled)
415+
{
416+
this.input.stop();
417+
}
418+
}
419+
420+
}
421+
422+
});

src/input/Input.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -253,7 +253,7 @@ Phaser.Input.prototype = {
253253
onTap: null,
254254
onHold: null,
255255

256-
// A linked list of interactive objects
256+
// A linked list of interactive objects, the InputHandler components (belong to Sprites) register themselves with this
257257
interactiveItems: new Phaser.LinkedList(),
258258

259259
/**

0 commit comments

Comments
 (0)