mirror of
https://github.com/wassname/phaser.git
synced 2026-07-08 00:10:32 +08:00
Implemented my own LinkedList class to make the new Input Handler easier to work with. And also just generally useful to have too.
This commit is contained in:
@@ -205,6 +205,9 @@ Phaser.Group.prototype = {
|
||||
* @param {string} index The <code>string</code> name of the member variable you want to sort on. Default value is "z".
|
||||
* @param {number} order A <code>Group</code> constant that defines the sort order. Possible values are <code>Group.ASCENDING</code> and <code>Group.DESCENDING</code>. Default value is <code>Group.ASCENDING</code>.
|
||||
*/
|
||||
|
||||
// http://www.chiark.greenend.org.uk/~sgtatham/algorithms/listsort.c
|
||||
|
||||
sort: function (index, order) {
|
||||
// if (typeof index === "undefined") { index = 'z'; }
|
||||
// if (typeof order === "undefined") { order = Phaser.Types.SORT_ASCENDING; }
|
||||
|
||||
@@ -0,0 +1,179 @@
|
||||
Phaser.LinkedList = function () {
|
||||
};
|
||||
|
||||
Phaser.LinkedList.prototype = {
|
||||
|
||||
_iNext: null,
|
||||
_iPrev: null,
|
||||
first: null,
|
||||
last: null,
|
||||
sprite: { name: 'HD' },
|
||||
|
||||
add: function (child) {
|
||||
|
||||
// If the list is empty
|
||||
if (this.first == null && this.last == null)
|
||||
{
|
||||
this.first = child;
|
||||
this.last = child;
|
||||
this._iNext = child;
|
||||
child._iPrev = this;
|
||||
return;
|
||||
}
|
||||
|
||||
// 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)
|
||||
this.last._iNext = child;
|
||||
|
||||
child._iPrev = this.last;
|
||||
|
||||
this.last = child;
|
||||
|
||||
},
|
||||
|
||||
remove: function (child) {
|
||||
|
||||
// If the list is empty
|
||||
if (this.first == null && this.last == null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
// The only node?
|
||||
if (this.first == child && this.last == child)
|
||||
{
|
||||
this.first = null;
|
||||
this.last = null;
|
||||
this._iNext = null;
|
||||
child._iNext = null;
|
||||
child._iPrev = null;
|
||||
return;
|
||||
}
|
||||
|
||||
var childPrev = child._iPrev;
|
||||
|
||||
// Tail node?
|
||||
if (child._iNext)
|
||||
{
|
||||
// Has another node after it?
|
||||
child._iNext._iPrev = child._iPrev;
|
||||
}
|
||||
|
||||
childPrev._iNext = child._iNext;
|
||||
|
||||
},
|
||||
|
||||
dump: function () {
|
||||
|
||||
console.log("\nNode\t\t|\t\tNext\t\t|\t\tPrev\t\t|\t\tFirst\t\t|\t\tLast");
|
||||
console.log("\t\t\t|\t\t\t\t\t|\t\t\t\t\t|\t\t\t\t\t|");
|
||||
|
||||
var nameNext = '-';
|
||||
var namePrev = '-';
|
||||
var nameFirst = '-';
|
||||
var nameLast = '-';
|
||||
|
||||
if (this._iNext)
|
||||
{
|
||||
nameNext = this._iNext.sprite.name;
|
||||
}
|
||||
|
||||
if (this._iPrev)
|
||||
{
|
||||
namePrev = this._iPrev.sprite.name;
|
||||
}
|
||||
|
||||
if (this.first)
|
||||
{
|
||||
nameFirst = this.first.sprite.name;
|
||||
}
|
||||
|
||||
if (this.last)
|
||||
{
|
||||
nameLast = this.last.sprite.name;
|
||||
}
|
||||
|
||||
if (typeof nameNext === 'undefined')
|
||||
{
|
||||
nameNext = '-';
|
||||
}
|
||||
|
||||
if (typeof namePrev === 'undefined')
|
||||
{
|
||||
namePrev = '-';
|
||||
}
|
||||
|
||||
if (typeof nameFirst === 'undefined')
|
||||
{
|
||||
nameFirst = '-';
|
||||
}
|
||||
|
||||
if (typeof nameLast === 'undefined')
|
||||
{
|
||||
nameLast = '-';
|
||||
}
|
||||
|
||||
console.log('HD' + '\t\t\t|\t\t' + nameNext + '\t\t\t|\t\t' + namePrev + '\t\t\t|\t\t' + nameFirst + '\t\t\t|\t\t' + nameLast);
|
||||
|
||||
var entity = this;
|
||||
|
||||
var testObject = entity.last._iNext;
|
||||
entity = entity.first;
|
||||
|
||||
do
|
||||
{
|
||||
var name = entity.sprite.name || '*';
|
||||
var nameNext = '-';
|
||||
var namePrev = '-';
|
||||
var nameFirst = '-';
|
||||
var nameLast = '-';
|
||||
|
||||
if (entity._iNext)
|
||||
{
|
||||
nameNext = entity._iNext.sprite.name;
|
||||
}
|
||||
|
||||
if (entity._iPrev)
|
||||
{
|
||||
namePrev = entity._iPrev.sprite.name;
|
||||
}
|
||||
|
||||
if (entity.first)
|
||||
{
|
||||
nameFirst = entity.first.sprite.name;
|
||||
}
|
||||
|
||||
if (entity.last)
|
||||
{
|
||||
nameLast = entity.last.sprite.name;
|
||||
}
|
||||
|
||||
if (typeof nameNext === 'undefined')
|
||||
{
|
||||
nameNext = '-';
|
||||
}
|
||||
|
||||
if (typeof namePrev === 'undefined')
|
||||
{
|
||||
namePrev = '-';
|
||||
}
|
||||
|
||||
if (typeof nameFirst === 'undefined')
|
||||
{
|
||||
nameFirst = '-';
|
||||
}
|
||||
|
||||
if (typeof nameLast === 'undefined')
|
||||
{
|
||||
nameLast = '-';
|
||||
}
|
||||
|
||||
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);
|
||||
|
||||
entity = entity._iNext;
|
||||
|
||||
}
|
||||
while(entity != testObject)
|
||||
|
||||
}
|
||||
|
||||
};
|
||||
@@ -10,9 +10,6 @@ Phaser.Sprite = function (game, x, y, key, frame) {
|
||||
// If exists = false then the Sprite isn't updated by the core game loop or physics subsystem at all
|
||||
this.exists = true;
|
||||
|
||||
// An "invisible" sprite isn't rendered at all
|
||||
this.visible = true;
|
||||
|
||||
// This is a handy little var your game can use to determine if a sprite is alive or not, it doesn't effect rendering
|
||||
this.alive = true;
|
||||
|
||||
@@ -58,6 +55,8 @@ Phaser.Sprite = function (game, x, y, key, frame) {
|
||||
this.currentFrame = this.game.cache.getFrame(key);
|
||||
}
|
||||
|
||||
this.input = new Phaser.InputHandler(this);
|
||||
|
||||
/**
|
||||
* The anchor sets the origin point of the texture.
|
||||
* The default is 0,0 this means the textures origin is the top left
|
||||
|
||||
@@ -253,6 +253,9 @@ Phaser.Input.prototype = {
|
||||
onTap: null,
|
||||
onHold: null,
|
||||
|
||||
// A linked list of interactive objects
|
||||
interactiveItems: new Phaser.LinkedList(),
|
||||
|
||||
/**
|
||||
* Starts the Input Manager running
|
||||
* @method start
|
||||
|
||||
@@ -0,0 +1,69 @@
|
||||
Phaser.InputHandler = function (sprite) {
|
||||
|
||||
this.game = sprite.game;
|
||||
this.sprite = sprite;
|
||||
|
||||
this.enabled = false;
|
||||
|
||||
// Linked list references
|
||||
this.last = this;
|
||||
this.first = this;
|
||||
|
||||
/**
|
||||
* The PriorityID controls which Sprite receives an Input event first if they should overlap.
|
||||
*/
|
||||
this.priorityID = 0;
|
||||
|
||||
this.isDragged = false;
|
||||
this.dragPixelPerfect = false;
|
||||
this.allowHorizontalDrag = true;
|
||||
this.allowVerticalDrag = true;
|
||||
this.bringToTop = false;
|
||||
this.snapOnDrag = false;
|
||||
this.snapOnRelease = false;
|
||||
this.snapX = 0;
|
||||
this.snapY = 0;
|
||||
|
||||
/**
|
||||
* Is this sprite allowed to be dragged by the mouse? true = yes, false = no
|
||||
* @default false
|
||||
*/
|
||||
this.draggable = false;
|
||||
|
||||
/**
|
||||
* A region of the game world within which the sprite is restricted during drag
|
||||
* @default null
|
||||
*/
|
||||
this.boundsRect = null;
|
||||
|
||||
/**
|
||||
* An Sprite the bounds of which this sprite is restricted during drag
|
||||
* @default null
|
||||
*/
|
||||
this.boundsSprite = null;
|
||||
|
||||
/**
|
||||
* If this object is set to consume the pointer event then it will stop all propogation from this object on.
|
||||
* For example if you had a stack of 6 sprites with the same priority IDs and one consumed the event, none of the others would receive it.
|
||||
* @type {bool}
|
||||
*/
|
||||
this.consumePointerEvent = false;
|
||||
|
||||
};
|
||||
|
||||
Phaser.InputHandler.prototype = {
|
||||
|
||||
game: null,
|
||||
sprite: null,
|
||||
|
||||
// Linked list references
|
||||
parent: null,
|
||||
_iNext: null,
|
||||
_iPrev: null,
|
||||
first: null,
|
||||
last: null,
|
||||
|
||||
enable: function () {
|
||||
},
|
||||
|
||||
};
|
||||
@@ -122,7 +122,6 @@ Phaser.Physics.Arcade.Body.prototype = {
|
||||
|
||||
},
|
||||
|
||||
/*
|
||||
postUpdate: function () {
|
||||
|
||||
this.sprite.x = this.x - this.offset.x + (this.sprite.anchor.x * this.width);
|
||||
@@ -134,7 +133,6 @@ Phaser.Physics.Arcade.Body.prototype = {
|
||||
}
|
||||
|
||||
},
|
||||
*/
|
||||
|
||||
checkWorldBounds: function () {
|
||||
|
||||
|
||||
Reference in New Issue
Block a user