Skip to content

Commit 981a4b1

Browse files
committed
Rename all setInteractive() arguments, and docs
1 parent 2c1249e commit 981a4b1

4 files changed

Lines changed: 38 additions & 29 deletions

File tree

src/gameobjects/GameObject.js

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -442,18 +442,27 @@ var GameObject = new Class({
442442
*
443443
* You can also provide an Input Configuration Object as the only argument to this method.
444444
*
445+
* @example
446+
* sprite.setInteractive();
447+
*
448+
* @example
449+
* sprite.setInteractive(new Phaser.Geom.Circle(45, 46, 45), Phaser.Geom.Circle.Contains);
450+
*
451+
* @example
452+
* graphics.setInteractive(new Phaser.Geom.Rectangle(0, 0, 128, 128), Phaser.Geom.Rectangle.Contains);
453+
*
445454
* @method Phaser.GameObjects.GameObject#setInteractive
446455
* @since 3.0.0
447456
*
448-
* @param {(Phaser.Types.Input.InputConfiguration|any)} [shape] - Either an input configuration object, or a geometric shape that defines the hit area for the Game Object. If not specified a Rectangle will be used.
449-
* @param {Phaser.Types.Input.HitAreaCallback} [callback] - A callback to be invoked when the Game Object is interacted with. If you provide a shape you must also provide a callback.
457+
* @param {(Phaser.Types.Input.InputConfiguration|any)} [hitArea] - Either an input configuration object, or a geometric shape that defines the hit area for the Game Object. If not given it will try to create a Rectangle based on the texture frame.
458+
* @param {Phaser.Types.Input.HitAreaCallback} [callback] - The callback that determines if the pointer is within the Hit Area shape or not. If you provide a shape you must also provide a callback.
450459
* @param {boolean} [dropZone=false] - Should this Game Object be treated as a drop zone target?
451460
*
452461
* @return {this} This GameObject.
453462
*/
454-
setInteractive: function (shape, callback, dropZone)
463+
setInteractive: function (hitArea, hitAreaCallback, dropZone)
455464
{
456-
this.scene.sys.input.enable(this, shape, callback, dropZone);
465+
this.scene.sys.input.enable(this, hitArea, hitAreaCallback, dropZone);
457466

458467
return this;
459468
},

src/gameobjects/zone/Zone.js

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -237,20 +237,20 @@ var Zone = new Class({
237237
* @method Phaser.GameObjects.Zone#setDropZone
238238
* @since 3.0.0
239239
*
240-
* @param {object} shape - A Geometry shape instance, such as Phaser.Geom.Ellipse, or your own custom shape.
241-
* @param {Phaser.Types.Input.HitAreaCallback} callback - A function that will return `true` if the given x/y coords it is sent are within the shape.
240+
* @param {object} hitArea - A Geometry shape instance, such as Phaser.Geom.Ellipse, or your own custom shape.
241+
* @param {Phaser.Types.Input.HitAreaCallback} hitAreaCallback - A function that will return `true` if the given x/y coords it is sent are within the shape.
242242
*
243243
* @return {this} This Game Object.
244244
*/
245-
setDropZone: function (shape, callback)
245+
setDropZone: function (hitArea, hitAreaCallback)
246246
{
247-
if (shape === undefined)
247+
if (hitArea === undefined)
248248
{
249249
this.setRectangleDropZone(this.width, this.height);
250250
}
251251
else if (!this.input)
252252
{
253-
this.setInteractive(shape, callback, true);
253+
this.setInteractive(hitArea, hitAreaCallback, true);
254254
}
255255

256256
return this;

src/input/InputPlugin.js

Lines changed: 19 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -862,13 +862,13 @@ var InputPlugin = new Class({
862862
* @since 3.0.0
863863
*
864864
* @param {Phaser.GameObjects.GameObject} gameObject - The Game Object to be enabled for input.
865-
* @param {(Phaser.Types.Input.InputConfiguration|any)} [shape] - Either an input configuration object, or a geometric shape that defines the hit area for the Game Object. If not specified a Rectangle will be used.
866-
* @param {Phaser.Types.Input.HitAreaCallback} [callback] - The 'contains' function to invoke to check if the pointer is within the hit area.
865+
* @param {(Phaser.Types.Input.InputConfiguration|any)} [hitArea] - Either an input configuration object, or a geometric shape that defines the hit area for the Game Object. If not specified a Rectangle will be used.
866+
* @param {Phaser.Types.Input.HitAreaCallback} [hitAreaCallback] - The 'contains' function to invoke to check if the pointer is within the hit area.
867867
* @param {boolean} [dropZone=false] - Is this Game Object a drop zone or not?
868868
*
869869
* @return {this} This Input Plugin.
870870
*/
871-
enable: function (gameObject, shape, callback, dropZone)
871+
enable: function (gameObject, hitArea, hitAreaCallback, dropZone)
872872
{
873873
if (dropZone === undefined) { dropZone = false; }
874874

@@ -880,7 +880,7 @@ var InputPlugin = new Class({
880880
else
881881
{
882882
// Create an InteractiveObject and enable it
883-
this.setHitArea(gameObject, shape, callback);
883+
this.setHitArea(gameObject, hitArea, hitAreaCallback);
884884
}
885885

886886
if (gameObject.input && dropZone && !gameObject.input.dropZone)
@@ -2120,14 +2120,14 @@ var InputPlugin = new Class({
21202120
* @since 3.0.0
21212121
*
21222122
* @param {(Phaser.GameObjects.GameObject|Phaser.GameObjects.GameObject[])} gameObjects - An array of Game Objects to set the hit area on.
2123-
* @param {(Phaser.Types.Input.InputConfiguration|any)} [shape] - Either an input configuration object, or a geometric shape that defines the hit area for the Game Object. If not specified a Rectangle will be used.
2124-
* @param {Phaser.Types.Input.HitAreaCallback} [callback] - The 'contains' function to invoke to check if the pointer is within the hit area.
2123+
* @param {(Phaser.Types.Input.InputConfiguration|any)} [hitArea] - Either an input configuration object, or a geometric shape that defines the hit area for the Game Object. If not specified a Rectangle will be used.
2124+
* @param {Phaser.Types.Input.HitAreaCallback} [hitAreaCallback] - The 'contains' function to invoke to check if the pointer is within the hit area.
21252125
*
21262126
* @return {this} This InputPlugin object.
21272127
*/
2128-
setHitArea: function (gameObjects, shape, callback)
2128+
setHitArea: function (gameObjects, hitArea, hitAreaCallback)
21292129
{
2130-
if (shape === undefined)
2130+
if (hitArea === undefined)
21312131
{
21322132
return this.setHitAreaFromTexture(gameObjects);
21332133
}
@@ -2145,12 +2145,12 @@ var InputPlugin = new Class({
21452145
var customHitArea = true;
21462146

21472147
// Config object?
2148-
if (IsPlainObject(shape))
2148+
if (IsPlainObject(hitArea))
21492149
{
2150-
var config = shape;
2150+
var config = hitArea;
21512151

2152-
shape = GetFastValue(config, 'hitArea', null);
2153-
callback = GetFastValue(config, 'hitAreaCallback', null);
2152+
hitArea = GetFastValue(config, 'hitArea', null);
2153+
hitAreaCallback = GetFastValue(config, 'hitAreaCallback', null);
21542154
draggable = GetFastValue(config, 'draggable', false);
21552155
dropZone = GetFastValue(config, 'dropZone', false);
21562156
cursor = GetFastValue(config, 'cursor', false);
@@ -2161,21 +2161,21 @@ var InputPlugin = new Class({
21612161

21622162
if (pixelPerfect)
21632163
{
2164-
shape = {};
2165-
callback = this.makePixelPerfect(alphaTolerance);
2164+
hitArea = {};
2165+
hitAreaCallback = this.makePixelPerfect(alphaTolerance);
21662166
}
21672167

21682168
// Still no hitArea or callback?
2169-
if (!shape || !callback)
2169+
if (!hitArea || !hitAreaCallback)
21702170
{
21712171
this.setHitAreaFromTexture(gameObjects);
21722172
customHitArea = false;
21732173
}
21742174
}
2175-
else if (typeof shape === 'function' && !callback)
2175+
else if (typeof hitArea === 'function' && !hitAreaCallback)
21762176
{
2177-
callback = shape;
2178-
shape = {};
2177+
hitAreaCallback = hitArea;
2178+
hitArea = {};
21792179
}
21802180

21812181
for (var i = 0; i < gameObjects.length; i++)
@@ -2188,7 +2188,7 @@ var InputPlugin = new Class({
21882188
continue;
21892189
}
21902190

2191-
var io = (!gameObject.input) ? CreateInteractiveObject(gameObject, shape, callback) : gameObject.input;
2191+
var io = (!gameObject.input) ? CreateInteractiveObject(gameObject, hitArea, hitAreaCallback) : gameObject.input;
21922192

21932193
io.customHitArea = customHitArea;
21942194
io.dropZone = dropZone;

src/input/typedefs/InputConfiguration.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
* @since 3.0.0
44
*
55
* @property {any} [hitArea] - The object / shape to use as the Hit Area. If not given it will try to create a Rectangle based on the texture frame.
6-
* @property {function} [hitAreaCallback] - The callback that determines if the pointer is within the Hit Area shape or not.
6+
* @property {Phaser.Types.Input.HitAreaCallback} [hitAreaCallback] - The callback that determines if the pointer is within the Hit Area shape or not.
77
* @property {boolean} [draggable=false] - If `true` the Interactive Object will be set to be draggable and emit drag events.
88
* @property {boolean} [dropZone=false] - If `true` the Interactive Object will be set to be a drop zone for draggable objects.
99
* @property {boolean} [useHandCursor=false] - If `true` the Interactive Object will set the `pointer` hand cursor when a pointer is over it. This is a short-cut for setting `cursor: 'pointer'`.

0 commit comments

Comments
 (0)