mirror of
https://github.com/photonstorm/phaser
synced 2024-11-23 05:03:37 +00:00
More node manipulations .. nearly there!
This commit is contained in:
parent
f4dab1847e
commit
ca0d1eb8af
1 changed files with 77 additions and 40 deletions
|
@ -26,6 +26,8 @@
|
|||
var e;
|
||||
var f;
|
||||
|
||||
var tests;
|
||||
|
||||
function create() {
|
||||
|
||||
s = game.add.sprite(game.world.centerX, game.world.centerY, 'sonic');
|
||||
|
@ -45,6 +47,8 @@
|
|||
e.name = 'e';
|
||||
f.name = 'f';
|
||||
|
||||
tests = [a,b,c,d,e,f];
|
||||
|
||||
game.input.onUp.add(runChange, this);
|
||||
|
||||
scanList(s);
|
||||
|
@ -64,30 +68,16 @@
|
|||
|
||||
if (index1 !== -1 && index2 !== -1)
|
||||
{
|
||||
// check for neighbours (cater for any order parameters)
|
||||
var node1Prev = node1._iPrev;
|
||||
var node1Next = node1._iNext;
|
||||
var node2Prev = node2._iPrev;
|
||||
var node2Next = node2._iNext;
|
||||
|
||||
// Check for neighbours (cater for any order parameters)
|
||||
if (node1._iNext == node2)
|
||||
{
|
||||
console.log('A-B neighbour swap');
|
||||
|
||||
// Pre-swap:
|
||||
// X next: a prev: - first: X last: d
|
||||
// a next: b prev: X first: a last: a
|
||||
// b next: c prev: a first: b last: b
|
||||
// c next: d prev: b first: c last: c
|
||||
// d next: - prev: c first: d last: d
|
||||
|
||||
// Post-swap:
|
||||
// X next: b prev: - first: X last: d
|
||||
// b next: a prev: X first: b last: b
|
||||
// a next: c prev: b first: a last: a
|
||||
// c next: d prev: a first: c last: c
|
||||
// d next: - prev: c first: d last: d
|
||||
|
||||
var node1Prev = node1._iPrev;
|
||||
var node1Next = node1._iNext;
|
||||
var node2Prev = node2._iPrev;
|
||||
var node2Next = node2._iNext;
|
||||
|
||||
// Starting
|
||||
// Node 1 (A) Node 2 (B) X C
|
||||
// Next: B Next: C Next: A Next: D
|
||||
|
@ -118,25 +108,6 @@
|
|||
{
|
||||
console.log('B-A neighbour swap');
|
||||
|
||||
// Pre-swap:
|
||||
// X next: a prev: - first: X last: d
|
||||
// a next: b prev: X first: a last: a
|
||||
// b next: c prev: a first: b last: b
|
||||
// c next: d prev: b first: c last: c
|
||||
// d next: - prev: c first: d last: d
|
||||
|
||||
// Post-swap:
|
||||
// X next: b prev: - first: X last: d
|
||||
// b next: a prev: X first: b last: b
|
||||
// a next: c prev: b first: a last: a
|
||||
// c next: d prev: a first: c last: c
|
||||
// d next: - prev: c first: d last: d
|
||||
|
||||
var node1Prev = node1._iPrev;
|
||||
var node1Next = node1._iNext;
|
||||
var node2Prev = node2._iPrev;
|
||||
var node2Next = node2._iNext;
|
||||
|
||||
// Starting
|
||||
// Node 1 (B) Node 2 (A) X C
|
||||
// Next: C Next: B Next: A Next: D
|
||||
|
@ -163,6 +134,67 @@
|
|||
node2Next._iPrev = node2;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
// Nodes are far apart
|
||||
console.log('Nodes are far apart');
|
||||
|
||||
// Pre-swap:
|
||||
// X next: a prev: - first: X last: d
|
||||
// a next: b prev: X first: a last: a
|
||||
// b next: c prev: a first: b last: b
|
||||
// c next: d prev: b first: c last: c
|
||||
// d next: e prev: c first: d last: d
|
||||
// e next: f prev: d first: e last: e
|
||||
// f next: - prev: e first: f last: f
|
||||
|
||||
// Post-swap:
|
||||
// X next: d prev: - first: X last: d ***
|
||||
// d next: b prev: X first: d last: d ***
|
||||
// b next: c prev: d first: b last: b ***
|
||||
// c next: a prev: b first: c last: c ***
|
||||
// a next: e prev: c first: a last: a ***
|
||||
// e next: f prev: a first: e last: e ***
|
||||
// f next: - prev: e first: f last: f
|
||||
|
||||
// Starting
|
||||
// Node 1 (A) Node 2 (D) N1 Prev (X) N1 Next (B) N2 Prev (C) N2 Next (E)
|
||||
// Next: B Next: E Next: A Next: C Next: D Next: F
|
||||
// Prev: X Prev: C Prev: - Prev: A Prev: B Prev: D
|
||||
|
||||
// Ending
|
||||
// Node 1 (A) Node 2 (D) N1 Prev (X) N1 Next (B) N2 Prev (C) N2 Next (E)
|
||||
// Next: E Next: B Next: D Next: C Next: A Next: F
|
||||
// Prev: C Prev: X Prev: - Prev: D Prev: B Prev: A
|
||||
|
||||
// Simple node 1-2 swap
|
||||
node1._iNext = node2Next;
|
||||
node1._iPrev = node2Prev;
|
||||
node2._iNext = node1Next;
|
||||
node2._iPrev = node1Prev;
|
||||
|
||||
// Now the head and tail for node 1.
|
||||
if (node1Prev)
|
||||
{
|
||||
node1Prev._iNext = node2;
|
||||
}
|
||||
|
||||
if (node1Next)
|
||||
{
|
||||
node1Next._iPrev = node2;
|
||||
}
|
||||
|
||||
// Now the head and tail for node 2.
|
||||
if (node2Prev)
|
||||
{
|
||||
node2Prev._iNext = node1;
|
||||
}
|
||||
|
||||
if (node2Next)
|
||||
{
|
||||
node2Next._iPrev = node1;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
scanList(s);
|
||||
|
@ -238,8 +270,13 @@
|
|||
|
||||
function render() {
|
||||
|
||||
for (var i = 0; i < tests.length; i++)
|
||||
{
|
||||
game.debug.renderText(tests[i].name, s.x + tests[i].x + tests[i].width / 2, s.y + tests[i].y - 20);
|
||||
}
|
||||
|
||||
// game.debug.renderSpriteCorners(s, false, false);
|
||||
// game.debug.renderSpriteInfo(s, 20, 32);
|
||||
game.debug.renderSpriteInfo(a, 20, 32);
|
||||
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue