From 089dfbb960e5882c0fc1dbc41318b4c443877384 Mon Sep 17 00:00:00 2001 From: photonstorm Date: Wed, 16 Apr 2014 21:39:04 +0100 Subject: [PATCH] Group.resetCursor will reset the Group cursor back to the start of the group, or to the given index value. --- README.md | 2 +- src/core/Group.js | 25 +++++++++++++++++++++++++ 2 files changed, 26 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 09d1c87a6..652730ac2 100644 --- a/README.md +++ b/README.md @@ -75,7 +75,7 @@ Version 2.0.4 - "Mos Shirare" - in development * Keyboard.reset has a new `hard` parameter which controls the severity of the reset. A soft reset doesn't remove any callbacks or event listeners. * Key.reset has a new `hard` parameter which controls the severity of the reset. A soft reset doesn't remove any callbacks or event listeners. * InputManager.resetLocked - If the Input Manager has been reset locked then all calls made to InputManager.reset, such as from a State change, are ignored. - +* Group.resetCursor will reset the Group cursor back to the start of the group, or to the given index value. ### Bug Fixes diff --git a/src/core/Group.js b/src/core/Group.js index 8039cc321..090456e54 100644 --- a/src/core/Group.js +++ b/src/core/Group.js @@ -353,6 +353,31 @@ Phaser.Group.prototype.updateZ = function () { }; +/** +* Sets the Group cursor to the first object in the Group. If the optional index parameter is given it sets the cursor to the object at that index instead. +* +* @method Phaser.Group#resetCursor +* @param {number} [index=0] - Set the cursor to point to a specific index. +* @return {*} The child the cursor now points to. +*/ +Phaser.Group.prototype.resetCursor = function (index) { + + if (typeof index === 'undefined') { index = 0; } + + if (index > this.children.length - 1) + { + index = 0; + } + + if (this.cursor) + { + this._cache[8] = index; + this.cursor = this.children[this._cache[8]]; + return this.cursor; + } + +}; + /** * Advances the Group cursor to the next object in the Group. If it's at the end of the Group it wraps around to the first object. *