2013-09-19 11:17:49 +00:00
|
|
|
/**
|
|
|
|
* @author Richard Davey <rich@photonstorm.com>
|
2014-02-05 05:54:25 +00:00
|
|
|
* @copyright 2014 Photon Storm Ltd.
|
2013-10-01 12:54:29 +00:00
|
|
|
* @license {@link https://github.com/photonstorm/phaser/blob/master/license.txt|MIT License}
|
2013-09-19 11:17:49 +00:00
|
|
|
*/
|
|
|
|
|
2013-09-08 23:30:44 +00:00
|
|
|
/**
|
2014-10-29 06:26:35 +00:00
|
|
|
* Create a new `Button` object. A Button is a special type of Sprite that is set-up to handle Pointer events automatically.
|
|
|
|
*
|
|
|
|
* The four states a Button responds to are:
|
2013-11-28 15:57:09 +00:00
|
|
|
*
|
|
|
|
* * 'Over' - when the Pointer moves over the Button. This is also commonly known as 'hover'.
|
|
|
|
* * 'Out' - when the Pointer that was previously over the Button moves out of it.
|
|
|
|
* * 'Down' - when the Pointer is pressed down on the Button. I.e. touched on a touch enabled device or clicked with the mouse.
|
|
|
|
* * 'Up' - when the Pointer that was pressed down on the Button is released again.
|
|
|
|
*
|
2014-10-29 06:26:35 +00:00
|
|
|
* A different texture/frame and activation sound can be specified for any of the states.
|
|
|
|
*
|
|
|
|
* Frames can be specified as either an integer (the frame ID) or a string (the frame name); the same values that can be used with a Sprite constructor.
|
2013-10-30 03:46:52 +00:00
|
|
|
*
|
2014-09-16 16:35:08 +00:00
|
|
|
* @class Phaser.Button
|
2013-09-16 14:37:30 +00:00
|
|
|
* @constructor
|
2014-07-11 17:02:40 +00:00
|
|
|
* @extends Phaser.Image
|
2013-09-19 14:34:48 +00:00
|
|
|
* @param {Phaser.Game} game Current game instance.
|
2013-12-31 17:03:09 +00:00
|
|
|
* @param {number} [x=0] - X position of the Button.
|
|
|
|
* @param {number} [y=0] - Y position of the Button.
|
2014-10-29 06:26:35 +00:00
|
|
|
* @param {string} [key] - The image key (in the Game.Cache) to use as the texture for this Button.
|
2013-10-30 03:46:52 +00:00
|
|
|
* @param {function} [callback] - The function to call when this Button is pressed.
|
|
|
|
* @param {object} [callbackContext] - The context in which the callback will be called (usually 'this').
|
2014-10-29 06:26:35 +00:00
|
|
|
* @param {string|integer} [overFrame] - The frame / frameName when the button is in the Over state.
|
|
|
|
* @param {string|integer} [outFrame] - The frame / frameName when the button is in the Out state.
|
|
|
|
* @param {string|integer} [downFrame] - The frame / frameName when the button is in the Down state.
|
|
|
|
* @param {string|integer} [upFrame] - The frame / frameName when the button is in the Up state.
|
2013-09-08 23:30:44 +00:00
|
|
|
*/
|
2013-12-31 17:03:09 +00:00
|
|
|
Phaser.Button = function (game, x, y, key, callback, callbackContext, overFrame, outFrame, downFrame, upFrame) {
|
2013-09-08 23:30:44 +00:00
|
|
|
|
|
|
|
x = x || 0;
|
|
|
|
y = y || 0;
|
|
|
|
key = key || null;
|
|
|
|
callback = callback || null;
|
|
|
|
callbackContext = callbackContext || this;
|
|
|
|
|
2014-07-11 17:02:40 +00:00
|
|
|
Phaser.Image.call(this, game, x, y, key, outFrame);
|
2013-09-08 23:30:44 +00:00
|
|
|
|
2014-03-23 07:59:28 +00:00
|
|
|
/**
|
2014-10-29 06:26:35 +00:00
|
|
|
* The Phaser Object Type.
|
|
|
|
* @property {number} type
|
2013-11-25 03:13:04 +00:00
|
|
|
*/
|
2013-09-12 20:54:41 +00:00
|
|
|
this.type = Phaser.BUTTON;
|
|
|
|
|
2014-03-23 07:59:28 +00:00
|
|
|
/**
|
2014-10-29 06:26:35 +00:00
|
|
|
* The frames for each state - can be integers or strings when set. Indexed by `Button.STATE_*`.
|
|
|
|
* @property {Array<string|integer|null>} _stateFrames
|
2013-11-25 03:13:04 +00:00
|
|
|
* @private
|
|
|
|
*/
|
2014-10-29 06:26:35 +00:00
|
|
|
this._stateFrames = [null, null, null, null];
|
2014-03-23 07:59:28 +00:00
|
|
|
|
|
|
|
/**
|
2014-10-29 06:26:35 +00:00
|
|
|
* The sounds and markers for each state.
|
|
|
|
* Indexed by `Button.STATE_* << 1` for the sound and `+1` for the marker; expanded on-demand.
|
|
|
|
* @property {object[]} _stateSounds
|
2013-11-25 03:13:04 +00:00
|
|
|
* @private
|
|
|
|
*/
|
2014-10-29 06:26:35 +00:00
|
|
|
this._stateSounds = [];
|
2014-03-23 07:59:28 +00:00
|
|
|
|
|
|
|
/**
|
2014-10-29 06:26:35 +00:00
|
|
|
* The Signal (or event) dispatched when this Button is in an Over state.
|
|
|
|
* @property {Phaser.Signal} onInputOver
|
2013-11-25 03:13:04 +00:00
|
|
|
*/
|
2014-10-29 06:26:35 +00:00
|
|
|
this.onInputOver = new Phaser.Signal();
|
2014-03-23 07:59:28 +00:00
|
|
|
|
|
|
|
/**
|
2014-10-29 06:26:35 +00:00
|
|
|
* The Signal (or event) dispatched when this Button is in an Out state.
|
|
|
|
* @property {Phaser.Signal} onInputOut
|
2013-11-25 03:13:04 +00:00
|
|
|
*/
|
2014-10-29 06:26:35 +00:00
|
|
|
this.onInputOut = new Phaser.Signal();
|
2014-03-23 07:59:28 +00:00
|
|
|
|
|
|
|
/**
|
2014-10-29 06:26:35 +00:00
|
|
|
* The Signal (or event) dispatched when this Button is in an Down state.
|
|
|
|
* @property {Phaser.Signal} onInputDown
|
2013-11-25 03:13:04 +00:00
|
|
|
*/
|
2014-10-29 06:26:35 +00:00
|
|
|
this.onInputDown = new Phaser.Signal();
|
2013-12-31 17:03:09 +00:00
|
|
|
|
2014-03-23 07:59:28 +00:00
|
|
|
/**
|
2014-10-29 06:26:35 +00:00
|
|
|
* The Signal (or event) dispatched when this Button is in an Up state.
|
|
|
|
* @property {Phaser.Signal} onInputUp
|
2013-11-25 03:13:04 +00:00
|
|
|
*/
|
2014-10-29 06:26:35 +00:00
|
|
|
this.onInputUp = new Phaser.Signal();
|
2013-09-08 23:30:44 +00:00
|
|
|
|
2014-05-13 10:04:39 +00:00
|
|
|
/**
|
2014-10-29 06:26:35 +00:00
|
|
|
* If true then onOver events (such as onOverSound) will only be triggered if the Pointer object causing them was the Mouse Pointer.
|
|
|
|
* The frame will still be changed as applicable.
|
|
|
|
* @property {boolean} onOverMouseOnly
|
2014-05-13 10:04:39 +00:00
|
|
|
* @default
|
|
|
|
*/
|
|
|
|
this.onOverMouseOnly = false;
|
2014-10-29 06:26:35 +00:00
|
|
|
|
2014-03-23 07:59:28 +00:00
|
|
|
/**
|
2014-10-29 06:26:35 +00:00
|
|
|
* When true the the texture frame will not be automatically switched on up/down/over/out events.
|
|
|
|
* @property {boolean} freezeFrames
|
2013-10-30 03:46:52 +00:00
|
|
|
* @default
|
|
|
|
*/
|
|
|
|
this.freezeFrames = false;
|
|
|
|
|
2013-11-04 20:43:59 +00:00
|
|
|
/**
|
2013-12-31 17:03:09 +00:00
|
|
|
* When the Button is touched / clicked and then released you can force it to enter a state of "out" instead of "up".
|
2013-11-04 20:43:59 +00:00
|
|
|
* @property {boolean} forceOut
|
|
|
|
* @default
|
|
|
|
*/
|
2013-12-31 17:03:09 +00:00
|
|
|
this.forceOut = false;
|
2013-11-04 20:43:59 +00:00
|
|
|
|
2014-02-07 18:55:29 +00:00
|
|
|
this.inputEnabled = true;
|
|
|
|
|
|
|
|
this.input.start(0, true);
|
|
|
|
|
2013-12-31 17:03:09 +00:00
|
|
|
this.setFrames(overFrame, outFrame, downFrame, upFrame);
|
2013-09-08 23:30:44 +00:00
|
|
|
|
2013-09-09 09:30:01 +00:00
|
|
|
if (callback !== null)
|
2013-09-08 23:30:44 +00:00
|
|
|
{
|
|
|
|
this.onInputUp.add(callback, callbackContext);
|
|
|
|
}
|
|
|
|
|
|
|
|
// Redirect the input events to here so we can handle animation updates, etc
|
|
|
|
this.events.onInputOver.add(this.onInputOverHandler, this);
|
|
|
|
this.events.onInputOut.add(this.onInputOutHandler, this);
|
|
|
|
this.events.onInputDown.add(this.onInputDownHandler, this);
|
|
|
|
this.events.onInputUp.add(this.onInputUpHandler, this);
|
|
|
|
|
2014-10-28 01:49:14 +00:00
|
|
|
this.events.onRemovedFromWorld.add(this.removedFromWorld, this);
|
|
|
|
|
2013-09-08 23:30:44 +00:00
|
|
|
};
|
|
|
|
|
2014-07-11 17:02:40 +00:00
|
|
|
Phaser.Button.prototype = Object.create(Phaser.Image.prototype);
|
2013-09-08 23:30:44 +00:00
|
|
|
Phaser.Button.prototype.constructor = Phaser.Button;
|
|
|
|
|
2014-10-29 06:26:35 +00:00
|
|
|
// State constants, useful to index into small state arrays.
|
|
|
|
// (Arranged by "expected likelines" of custom frames/sounds and may change - don't hard-code.)
|
|
|
|
Phaser.Button.STATE_OVER = 0;
|
|
|
|
Phaser.Button.STATE_DOWN = 1;
|
|
|
|
Phaser.Button.STATE_UP = 2;
|
|
|
|
Phaser.Button.STATE_OUT = 3;
|
|
|
|
|
2013-09-16 14:37:30 +00:00
|
|
|
/**
|
2013-12-31 17:03:09 +00:00
|
|
|
* Clears all of the frames set on this Button.
|
|
|
|
*
|
2014-10-29 06:26:35 +00:00
|
|
|
* @method Phaser.Button#clearFrames
|
2013-12-31 17:03:09 +00:00
|
|
|
*/
|
|
|
|
Phaser.Button.prototype.clearFrames = function () {
|
|
|
|
|
2014-10-29 06:26:35 +00:00
|
|
|
this.setFrames(null, null, null, null);
|
2013-12-31 17:03:09 +00:00
|
|
|
|
2014-03-23 08:40:24 +00:00
|
|
|
};
|
2013-12-31 17:03:09 +00:00
|
|
|
|
2014-10-28 01:49:14 +00:00
|
|
|
/**
|
|
|
|
* Called when this Button is removed from the World.
|
|
|
|
*
|
2014-10-29 06:26:35 +00:00
|
|
|
* @method Phaser.Button#removedFromWorld
|
|
|
|
* @protected
|
2014-10-28 01:49:14 +00:00
|
|
|
*/
|
|
|
|
Phaser.Button.prototype.removedFromWorld = function () {
|
|
|
|
|
|
|
|
this.inputEnabled = false;
|
|
|
|
|
|
|
|
};
|
|
|
|
|
2013-12-31 17:03:09 +00:00
|
|
|
/**
|
2014-10-29 06:26:35 +00:00
|
|
|
* Set the frame name/ID for the given state.
|
2013-09-16 14:37:30 +00:00
|
|
|
*
|
2014-10-29 06:26:35 +00:00
|
|
|
* @method Phaser.Button#setStateFrame
|
|
|
|
* @private
|
|
|
|
* @param {integer} state - See `Button.STATE_*`
|
|
|
|
* @param {number|string} frame - The number or string representing the frame.
|
|
|
|
* @param {boolean} switchImmediately - Immediately switch to the frame if it was set - and this is true.
|
2013-09-16 14:37:30 +00:00
|
|
|
*/
|
2014-10-29 06:26:35 +00:00
|
|
|
Phaser.Button.prototype.setStateFrame = function (state, frame, switchImmediately)
|
|
|
|
{
|
|
|
|
|
|
|
|
if (frame != null) // Anything but null/undefined
|
2013-09-09 09:30:01 +00:00
|
|
|
{
|
2014-10-29 06:26:35 +00:00
|
|
|
this._stateFrames[state] = frame;
|
2014-03-23 07:59:28 +00:00
|
|
|
|
2014-10-29 06:26:35 +00:00
|
|
|
if (switchImmediately)
|
2013-09-09 09:30:01 +00:00
|
|
|
{
|
2014-10-29 06:26:35 +00:00
|
|
|
this.changeStateFrame(frame);
|
2013-09-09 09:30:01 +00:00
|
|
|
}
|
|
|
|
}
|
2014-10-29 06:26:35 +00:00
|
|
|
else
|
2013-09-09 09:30:01 +00:00
|
|
|
{
|
2014-10-29 06:26:35 +00:00
|
|
|
this._stateFrames[state] = null;
|
|
|
|
}
|
2013-09-30 16:12:22 +00:00
|
|
|
|
2014-10-29 06:26:35 +00:00
|
|
|
};
|
2013-09-30 16:12:22 +00:00
|
|
|
|
2014-10-29 06:26:35 +00:00
|
|
|
/**
|
|
|
|
* Change the frame to that of the given state, _if_ the state has a frame assigned _and_ if the frames are not currently "frozen".
|
|
|
|
*
|
|
|
|
* @method Phaser.Button#changeStateFrame
|
|
|
|
* @private
|
|
|
|
* @param {integer} state - See `Button.STATE_*`
|
|
|
|
* @return {boolean} True only if the frame was assigned a value, possibly the same one it already had.
|
|
|
|
*/
|
|
|
|
Phaser.Button.prototype.changeStateFrame = function (state) {
|
|
|
|
|
|
|
|
if (this.freezeFrames)
|
|
|
|
{
|
|
|
|
return false;
|
2013-09-09 09:30:01 +00:00
|
|
|
}
|
|
|
|
|
2014-10-29 06:26:35 +00:00
|
|
|
var frame = this._stateFrames[state];
|
|
|
|
if (typeof frame === 'string')
|
2013-09-09 09:30:01 +00:00
|
|
|
{
|
2014-10-29 06:26:35 +00:00
|
|
|
this.frameName = frame;
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
else if (typeof frame === 'number')
|
|
|
|
{
|
|
|
|
this.frame = frame;
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
return false;
|
|
|
|
}
|
2013-09-30 16:12:22 +00:00
|
|
|
|
2014-10-29 06:26:35 +00:00
|
|
|
};
|
2013-09-30 16:12:22 +00:00
|
|
|
|
2014-10-29 06:26:35 +00:00
|
|
|
/**
|
|
|
|
* Used to manually set the frames that will be used for the different states of the Button.
|
|
|
|
*
|
|
|
|
* Frames can be specified as either an integer (the frame ID) or a string (the frame name); these are the same values that can be used with a Sprite constructor.
|
|
|
|
*
|
|
|
|
* @method Phaser.Button#setFrames
|
|
|
|
* @public
|
|
|
|
* @param {string|integer} [overFrame] - The frame / frameName when the button is in the Over state.
|
|
|
|
* @param {string|integer} [outFrame] - The frame / frameName when the button is in the Out state.
|
|
|
|
* @param {string|integer} [downFrame] - The frame / frameName when the button is in the Down state.
|
|
|
|
* @param {string|integer} [upFrame] - The frame / frameName when the button is in the Up state.
|
|
|
|
*/
|
|
|
|
Phaser.Button.prototype.setFrames = function (overFrame, outFrame, downFrame, upFrame) {
|
|
|
|
|
|
|
|
this.setStateFrame(Phaser.Button.STATE_OVER, overFrame, this.input.pointerOver());
|
|
|
|
this.setStateFrame(Phaser.Button.STATE_OUT, outFrame, !this.input.pointerOver());
|
|
|
|
this.setStateFrame(Phaser.Button.STATE_DOWN, downFrame, this.input.pointerDown());
|
|
|
|
this.setStateFrame(Phaser.Button.STATE_UP, upFrame, this.input.pointerUp());
|
|
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Set the sound/marker for the given state.
|
|
|
|
*
|
|
|
|
* @method Phaser.Button#setStateSound
|
|
|
|
* @private
|
|
|
|
* @param {integer} state - See `Button.STATE_*`
|
|
|
|
* @param {Phaser.Sound|Phaser.AudioSprite} [sound] - Sound.
|
|
|
|
* @param {string} [marker=null] - Sound marker.
|
|
|
|
*/
|
|
|
|
Phaser.Button.prototype.setStateSound = function (state, sound, marker) {
|
|
|
|
|
|
|
|
var soundIndex = state << 1;
|
|
|
|
var markerIndex = soundIndex + 1;
|
|
|
|
var sounds = this._stateSounds;
|
|
|
|
|
|
|
|
if (sound instanceof Phaser.Sound || sound instanceof Phaser.AudioSprite)
|
|
|
|
{
|
|
|
|
while (markerIndex > sounds.length) { // Dense null
|
|
|
|
sounds.push(null);
|
2013-09-09 09:30:01 +00:00
|
|
|
}
|
|
|
|
|
2014-10-29 06:26:35 +00:00
|
|
|
sounds[soundIndex] = sound;
|
|
|
|
sounds[markerIndex] = typeof marker === 'string' ? marker : null;
|
|
|
|
}
|
|
|
|
else if (markerIndex < sounds.length)
|
2013-12-31 17:03:09 +00:00
|
|
|
{
|
2014-10-29 06:26:35 +00:00
|
|
|
// Only null if set-through
|
|
|
|
sounds[soundIndex] = null;
|
|
|
|
sounds[markerIndex] = null;
|
|
|
|
}
|
2013-12-31 17:03:09 +00:00
|
|
|
|
2014-10-29 06:26:35 +00:00
|
|
|
};
|
2013-12-31 17:03:09 +00:00
|
|
|
|
2014-10-29 06:26:35 +00:00
|
|
|
/**
|
|
|
|
* Play the sound for the given state, _if_ the state has a sound assigned.
|
|
|
|
*
|
|
|
|
* @method Phaser.Button#playStateSound
|
|
|
|
* @private
|
|
|
|
* @param {integer} state - See `Button.STATE_*`
|
|
|
|
* @return {boolean} True only if a sound was played.
|
|
|
|
*/
|
|
|
|
Phaser.Button.prototype.playStateSound = function (state) {
|
|
|
|
|
|
|
|
var soundIndex = state << 1;
|
|
|
|
var markerIndex = soundIndex + 1;
|
|
|
|
var sounds = this._stateSounds;
|
|
|
|
|
|
|
|
var sound = sounds[soundIndex];
|
|
|
|
if (sound)
|
|
|
|
{
|
|
|
|
var marker = sounds[markerIndex];
|
|
|
|
sound.play(marker);
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
return false;
|
2013-12-31 17:03:09 +00:00
|
|
|
}
|
|
|
|
|
2013-09-09 09:30:01 +00:00
|
|
|
};
|
|
|
|
|
2013-10-01 12:54:29 +00:00
|
|
|
/**
|
2013-10-30 03:46:52 +00:00
|
|
|
* Sets the sounds to be played whenever this Button is interacted with. Sounds can be either full Sound objects, or markers pointing to a section of a Sound object.
|
|
|
|
* The most common forms of sounds are 'hover' effects and 'click' effects, which is why the order of the parameters is overSound then downSound.
|
|
|
|
*
|
2014-10-29 06:26:35 +00:00
|
|
|
* Call this function with no parameters to reset all sounds on this Button.
|
|
|
|
*
|
|
|
|
* @method Phaser.Button#setSounds
|
|
|
|
* @public
|
2014-10-20 22:17:05 +00:00
|
|
|
* @param {Phaser.Sound|Phaser.AudioSprite} [overSound] - Over Button Sound.
|
2013-10-30 03:46:52 +00:00
|
|
|
* @param {string} [overMarker] - Over Button Sound Marker.
|
2014-10-20 22:17:05 +00:00
|
|
|
* @param {Phaser.Sound|Phaser.AudioSprite} [downSound] - Down Button Sound.
|
2013-10-30 03:46:52 +00:00
|
|
|
* @param {string} [downMarker] - Down Button Sound Marker.
|
2014-10-20 22:17:05 +00:00
|
|
|
* @param {Phaser.Sound|Phaser.AudioSprite} [outSound] - Out Button Sound.
|
2013-10-30 03:46:52 +00:00
|
|
|
* @param {string} [outMarker] - Out Button Sound Marker.
|
2014-10-20 22:17:05 +00:00
|
|
|
* @param {Phaser.Sound|Phaser.AudioSprite} [upSound] - Up Button Sound.
|
2013-10-30 03:46:52 +00:00
|
|
|
* @param {string} [upMarker] - Up Button Sound Marker.
|
|
|
|
*/
|
|
|
|
Phaser.Button.prototype.setSounds = function (overSound, overMarker, downSound, downMarker, outSound, outMarker, upSound, upMarker) {
|
|
|
|
|
2014-10-29 06:26:35 +00:00
|
|
|
this.setStateSound(Phaser.Button.STATE_OVER, overSound, overMarker);
|
|
|
|
this.setStateSound(Phaser.Button.STATE_OUT, outSound, outMarker);
|
|
|
|
this.setStateSound(Phaser.Button.STATE_DOWN, downSound, downMarker);
|
|
|
|
this.setStateSound(Phaser.Button.STATE_UP, upSound, upMarker);
|
2013-10-30 03:46:52 +00:00
|
|
|
|
2014-03-23 08:40:24 +00:00
|
|
|
};
|
2013-10-30 03:46:52 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* The Sound to be played when a Pointer moves over this Button.
|
|
|
|
*
|
2014-10-29 06:26:35 +00:00
|
|
|
* @method Phaser.Button#setOverSound
|
|
|
|
* @public
|
2014-10-20 22:17:05 +00:00
|
|
|
* @param {Phaser.Sound|Phaser.AudioSprite} sound - The Sound that will be played.
|
2013-10-30 03:46:52 +00:00
|
|
|
* @param {string} [marker] - A Sound Marker that will be used in the playback.
|
|
|
|
*/
|
|
|
|
Phaser.Button.prototype.setOverSound = function (sound, marker) {
|
|
|
|
|
2014-10-29 06:26:35 +00:00
|
|
|
this.setStateSound(Phaser.Button.STATE_OVER, sound, marker);
|
2013-10-30 03:46:52 +00:00
|
|
|
|
2014-03-23 08:40:24 +00:00
|
|
|
};
|
2013-10-30 03:46:52 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* The Sound to be played when a Pointer moves out of this Button.
|
|
|
|
*
|
2014-10-29 06:26:35 +00:00
|
|
|
* @method Phaser.Button#setOutSound
|
|
|
|
* @public
|
2014-10-20 22:17:05 +00:00
|
|
|
* @param {Phaser.Sound|Phaser.AudioSprite} sound - The Sound that will be played.
|
2013-10-30 03:46:52 +00:00
|
|
|
* @param {string} [marker] - A Sound Marker that will be used in the playback.
|
|
|
|
*/
|
|
|
|
Phaser.Button.prototype.setOutSound = function (sound, marker) {
|
|
|
|
|
2014-10-29 06:26:35 +00:00
|
|
|
this.setStateSound(Phaser.Button.STATE_OUT, sound, marker);
|
2013-10-30 03:46:52 +00:00
|
|
|
|
2014-03-23 08:40:24 +00:00
|
|
|
};
|
2013-10-30 03:46:52 +00:00
|
|
|
|
|
|
|
/**
|
2013-12-31 17:03:09 +00:00
|
|
|
* The Sound to be played when a Pointer presses down on this Button.
|
2013-10-01 12:54:29 +00:00
|
|
|
*
|
2014-10-29 06:26:35 +00:00
|
|
|
* @method Phaser.Button#setDownSound
|
|
|
|
* @public
|
2014-10-20 22:17:05 +00:00
|
|
|
* @param {Phaser.Sound|Phaser.AudioSprite} sound - The Sound that will be played.
|
2013-10-30 03:46:52 +00:00
|
|
|
* @param {string} [marker] - A Sound Marker that will be used in the playback.
|
|
|
|
*/
|
2013-12-31 17:03:09 +00:00
|
|
|
Phaser.Button.prototype.setDownSound = function (sound, marker) {
|
2013-10-30 03:46:52 +00:00
|
|
|
|
2014-10-29 06:26:35 +00:00
|
|
|
this.setStateSound(Phaser.Button.STATE_DOWN, sound, marker);
|
2013-10-30 03:46:52 +00:00
|
|
|
|
2014-03-23 08:40:24 +00:00
|
|
|
};
|
2013-10-30 03:46:52 +00:00
|
|
|
|
|
|
|
/**
|
2013-12-31 17:03:09 +00:00
|
|
|
* The Sound to be played when a Pointer has pressed down and is released from this Button.
|
2013-10-30 03:46:52 +00:00
|
|
|
*
|
2014-10-29 06:26:35 +00:00
|
|
|
* @method Phaser.Button#setUpSound
|
|
|
|
* @public
|
2014-10-20 22:17:05 +00:00
|
|
|
* @param {Phaser.Sound|Phaser.AudioSprite} sound - The Sound that will be played.
|
2013-10-30 03:46:52 +00:00
|
|
|
* @param {string} [marker] - A Sound Marker that will be used in the playback.
|
|
|
|
*/
|
2013-12-31 17:03:09 +00:00
|
|
|
Phaser.Button.prototype.setUpSound = function (sound, marker) {
|
2013-10-30 03:46:52 +00:00
|
|
|
|
2014-10-29 06:26:35 +00:00
|
|
|
this.setStateSound(Phaser.Button.STATE_UP, sound, marker);
|
2013-10-30 03:46:52 +00:00
|
|
|
|
2014-03-23 08:40:24 +00:00
|
|
|
};
|
2013-10-30 03:46:52 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Internal function that handles input events.
|
|
|
|
*
|
2014-10-29 06:26:35 +00:00
|
|
|
* @method Phaser.Button#onInputOverHandler
|
2013-10-30 03:46:52 +00:00
|
|
|
* @protected
|
2013-12-31 17:03:09 +00:00
|
|
|
* @param {Phaser.Button} sprite - The Button that the event occured on.
|
2013-10-30 03:46:52 +00:00
|
|
|
* @param {Phaser.Pointer} pointer - The Pointer that activated the Button.
|
2013-10-01 12:54:29 +00:00
|
|
|
*/
|
2013-12-31 17:03:09 +00:00
|
|
|
Phaser.Button.prototype.onInputOverHandler = function (sprite, pointer) {
|
2013-09-08 23:30:44 +00:00
|
|
|
|
2014-10-21 21:43:42 +00:00
|
|
|
// If the Pointer was only just released then we don't fire an over event
|
|
|
|
if (pointer.justReleased())
|
|
|
|
{
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2014-10-29 06:26:35 +00:00
|
|
|
this.changeStateFrame(Phaser.Button.STATE_OVER);
|
2013-09-08 23:30:44 +00:00
|
|
|
|
2014-05-13 10:04:39 +00:00
|
|
|
if (this.onOverMouseOnly && !pointer.isMouse)
|
|
|
|
{
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2014-10-29 06:26:35 +00:00
|
|
|
this.playStateSound(Phaser.Button.STATE_OVER);
|
2013-10-30 03:46:52 +00:00
|
|
|
|
2013-09-08 23:30:44 +00:00
|
|
|
if (this.onInputOver)
|
|
|
|
{
|
|
|
|
this.onInputOver.dispatch(this, pointer);
|
|
|
|
}
|
2014-05-13 10:04:39 +00:00
|
|
|
|
2013-09-08 23:30:44 +00:00
|
|
|
};
|
|
|
|
|
2013-10-01 12:54:29 +00:00
|
|
|
/**
|
2013-10-30 03:46:52 +00:00
|
|
|
* Internal function that handles input events.
|
2013-10-01 12:54:29 +00:00
|
|
|
*
|
2014-10-29 06:26:35 +00:00
|
|
|
* @method Phaser.Button#onInputOutHandler
|
2013-10-30 03:46:52 +00:00
|
|
|
* @protected
|
2013-12-31 17:03:09 +00:00
|
|
|
* @param {Phaser.Button} sprite - The Button that the event occured on.
|
2013-10-30 03:46:52 +00:00
|
|
|
* @param {Phaser.Pointer} pointer - The Pointer that activated the Button.
|
2013-10-01 12:54:29 +00:00
|
|
|
*/
|
2013-12-31 17:03:09 +00:00
|
|
|
Phaser.Button.prototype.onInputOutHandler = function (sprite, pointer) {
|
2013-09-08 23:30:44 +00:00
|
|
|
|
2014-10-29 06:26:35 +00:00
|
|
|
this.changeStateFrame(Phaser.Button.STATE_OUT);
|
2013-09-08 23:30:44 +00:00
|
|
|
|
2014-10-29 06:26:35 +00:00
|
|
|
this.playStateSound(Phaser.Button.STATE_OUT);
|
2013-10-30 03:46:52 +00:00
|
|
|
|
2013-09-08 23:30:44 +00:00
|
|
|
if (this.onInputOut)
|
|
|
|
{
|
|
|
|
this.onInputOut.dispatch(this, pointer);
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2013-10-01 12:54:29 +00:00
|
|
|
/**
|
2013-10-30 03:46:52 +00:00
|
|
|
* Internal function that handles input events.
|
2013-10-01 12:54:29 +00:00
|
|
|
*
|
2014-10-29 06:26:35 +00:00
|
|
|
* @method Phaser.Button#onInputDownHandler
|
2013-10-30 03:46:52 +00:00
|
|
|
* @protected
|
2013-12-31 17:03:09 +00:00
|
|
|
* @param {Phaser.Button} sprite - The Button that the event occured on.
|
2013-10-30 03:46:52 +00:00
|
|
|
* @param {Phaser.Pointer} pointer - The Pointer that activated the Button.
|
2013-10-01 12:54:29 +00:00
|
|
|
*/
|
2013-12-31 17:03:09 +00:00
|
|
|
Phaser.Button.prototype.onInputDownHandler = function (sprite, pointer) {
|
2013-09-08 23:30:44 +00:00
|
|
|
|
2014-10-29 06:26:35 +00:00
|
|
|
this.changeStateFrame(Phaser.Button.STATE_DOWN);
|
2013-09-08 23:30:44 +00:00
|
|
|
|
2014-10-29 06:26:35 +00:00
|
|
|
this.playStateSound(Phaser.Button.STATE_DOWN);
|
2013-10-30 03:46:52 +00:00
|
|
|
|
2013-09-08 23:30:44 +00:00
|
|
|
if (this.onInputDown)
|
|
|
|
{
|
|
|
|
this.onInputDown.dispatch(this, pointer);
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2013-10-01 12:54:29 +00:00
|
|
|
/**
|
2013-10-30 03:46:52 +00:00
|
|
|
* Internal function that handles input events.
|
2013-10-01 12:54:29 +00:00
|
|
|
*
|
2014-10-29 06:26:35 +00:00
|
|
|
* @method Phaser.Button#onInputUpHandler
|
2013-10-30 03:46:52 +00:00
|
|
|
* @protected
|
2013-12-31 17:03:09 +00:00
|
|
|
* @param {Phaser.Button} sprite - The Button that the event occured on.
|
2013-10-30 03:46:52 +00:00
|
|
|
* @param {Phaser.Pointer} pointer - The Pointer that activated the Button.
|
2013-10-01 12:54:29 +00:00
|
|
|
*/
|
2013-12-31 17:03:09 +00:00
|
|
|
Phaser.Button.prototype.onInputUpHandler = function (sprite, pointer, isOver) {
|
2013-09-08 23:30:44 +00:00
|
|
|
|
2014-10-29 06:26:35 +00:00
|
|
|
this.playStateSound(Phaser.Button.STATE_UP);
|
2013-12-31 17:03:09 +00:00
|
|
|
|
2014-10-29 06:26:35 +00:00
|
|
|
// Input dispatched early, before state change (but after sound)
|
2013-12-31 17:03:09 +00:00
|
|
|
if (this.onInputUp)
|
|
|
|
{
|
|
|
|
this.onInputUp.dispatch(this, pointer, isOver);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (this.freezeFrames)
|
|
|
|
{
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (this.forceOut)
|
|
|
|
{
|
2014-10-29 06:26:35 +00:00
|
|
|
this.changeStateFrame(Phaser.Button.STATE_OUT);
|
2013-12-31 17:03:09 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2014-10-29 06:26:35 +00:00
|
|
|
var changedUp = this.changeStateFrame(Phaser.Button.STATE_UP);
|
|
|
|
if (!changedUp)
|
2013-10-02 19:18:24 +00:00
|
|
|
{
|
2014-10-29 06:26:35 +00:00
|
|
|
// No Up frame to show..
|
2013-12-31 17:03:09 +00:00
|
|
|
if (isOver)
|
|
|
|
{
|
2014-10-29 06:26:35 +00:00
|
|
|
this.changeStateFrame(Phaser.Button.STATE_OVER);
|
2013-12-31 17:03:09 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2014-10-29 06:26:35 +00:00
|
|
|
this.changeStateFrame(Phaser.Button.STATE_OUT);
|
2013-12-31 17:03:09 +00:00
|
|
|
}
|
2013-10-02 19:18:24 +00:00
|
|
|
}
|
2013-09-08 23:30:44 +00:00
|
|
|
}
|
|
|
|
|
2013-12-31 17:03:09 +00:00
|
|
|
};
|