mirror of
https://github.com/photonstorm/phaser
synced 2025-02-17 06:28:30 +00:00
New Interactive Object created.
Pointer events now dispatch more details. Interactive Object used internally everywhere. Hit Test updated to handle it.
This commit is contained in:
parent
9a34ce71ac
commit
0d925b9cc0
10 changed files with 101 additions and 53 deletions
|
@ -1,4 +1,4 @@
|
|||
var CHECKSUM = {
|
||||
build: 'c34efc00-6b3d-11e7-9a3d-a54976e6b2b6'
|
||||
build: 'abf1bcd0-6b58-11e7-abf0-e311646824f1'
|
||||
};
|
||||
module.exports = CHECKSUM;
|
21
v3/src/input/InteractiveObject.js
Normal file
21
v3/src/input/InteractiveObject.js
Normal file
|
@ -0,0 +1,21 @@
|
|||
// Phaser.Input.InteractiveObject
|
||||
|
||||
var InteractiveObject = function (gameObject, hitArea, hitAreaCallback)
|
||||
{
|
||||
return {
|
||||
gameObject: gameObject,
|
||||
|
||||
hitArea: hitArea,
|
||||
hitAreaCallback: hitAreaCallback,
|
||||
|
||||
localX: 0,
|
||||
localY: 0,
|
||||
|
||||
isOver: false,
|
||||
isDown: false,
|
||||
|
||||
isDragged: false
|
||||
};
|
||||
};
|
||||
|
||||
module.exports = InteractiveObject;
|
|
@ -10,20 +10,13 @@ var Pointer = new Class({
|
|||
{
|
||||
this.manager = manager;
|
||||
|
||||
this.event;
|
||||
|
||||
this.button = 0;
|
||||
|
||||
this.x = 0;
|
||||
this.y = 0;
|
||||
|
||||
this.clientX = 0;
|
||||
this.clientY = 0;
|
||||
|
||||
this.pageX = 0;
|
||||
this.pageY = 0;
|
||||
|
||||
this.screenX = 0;
|
||||
this.screenY = 0;
|
||||
|
||||
this.isDown = false;
|
||||
|
||||
this.dirty = false;
|
||||
|
@ -48,38 +41,46 @@ var Pointer = new Class({
|
|||
this.button = event.button;
|
||||
}
|
||||
|
||||
this.clientX = event.clientX;
|
||||
this.clientY = event.clientY;
|
||||
|
||||
this.pageX = event.pageX;
|
||||
this.pageY = event.pageY;
|
||||
|
||||
this.screenX = event.screenX;
|
||||
this.screenY = event.screenY;
|
||||
this.event = event;
|
||||
|
||||
this.x = this.manager.transformX(event.pageX);
|
||||
this.y = this.manager.transformY(event.pageY);
|
||||
|
||||
this.dirty = true;
|
||||
|
||||
this.justMoved = true;
|
||||
},
|
||||
|
||||
down: function (event)
|
||||
{
|
||||
this.dirty = true;
|
||||
if (event.button !== undefined)
|
||||
{
|
||||
this.button = event.button;
|
||||
}
|
||||
|
||||
this.x = event.x;
|
||||
this.y = event.y;
|
||||
this.event = event;
|
||||
|
||||
this.x = this.manager.transformX(event.pageX);
|
||||
this.y = this.manager.transformY(event.pageY);
|
||||
|
||||
this.dirty = true;
|
||||
|
||||
this.justDown = true;
|
||||
},
|
||||
|
||||
up: function (event)
|
||||
{
|
||||
this.dirty = true;
|
||||
if (event.button !== undefined)
|
||||
{
|
||||
this.button = event.button;
|
||||
}
|
||||
|
||||
this.x = event.x;
|
||||
this.y = event.y;
|
||||
this.event = event;
|
||||
|
||||
this.x = this.manager.transformX(event.pageX);
|
||||
this.y = this.manager.transformY(event.pageY);
|
||||
|
||||
this.dirty = true;
|
||||
|
||||
this.justUp = true;
|
||||
}
|
||||
|
|
|
@ -1,8 +1,9 @@
|
|||
var GetTransformedPoint = require('./GetTransformedPoint');
|
||||
var PointWithinGameObject = require('./PointWithinGameObject');
|
||||
var PointWithinInteractiveObject = require('./PointWithinInteractiveObject');
|
||||
|
||||
// Will always return an array.
|
||||
// Array contains matching Game Objects.
|
||||
// Array contains matching Interactive Objects.
|
||||
// Array will be empty if no objects were matched.
|
||||
|
||||
var HitTest = function (tempMatrix, x, y, gameObjectArray, camera, output)
|
||||
|
@ -20,17 +21,17 @@ var HitTest = function (tempMatrix, x, y, gameObjectArray, camera, output)
|
|||
var scrollX = camera.scrollX;
|
||||
var scrollY = camera.scrollY;
|
||||
var screenPoint = camera.cameraToScreen({ x: x, y: y });
|
||||
var culled = camera.cull(gameObjectArray);
|
||||
var culled = camera.cullHitTest(gameObjectArray);
|
||||
|
||||
for (var i = 0; i < culled.length; i++)
|
||||
{
|
||||
var object = culled[i];
|
||||
var gameObject = object.gameObject;
|
||||
|
||||
var tpoint = GetTransformedPoint(tempMatrix, object, screenPoint.x + scrollX * object.scrollFactorX, screenPoint.y + scrollY * object.scrollFactorY);
|
||||
var tpoint = GetTransformedPoint(tempMatrix, gameObject, screenPoint.x + scrollX * gameObject.scrollFactorX, screenPoint.y + scrollY * gameObject.scrollFactorY);
|
||||
|
||||
if (PointWithinGameObject(object, tpoint.x, tpoint.y))
|
||||
if (PointWithinInteractiveObject(object, tpoint.x, tpoint.y))
|
||||
{
|
||||
// output.push({ gameObject: object, x: tpoint.x, y: tpoint.y });
|
||||
output.push(object);
|
||||
}
|
||||
}
|
||||
|
|
21
v3/src/input/components/PointWithinInteractiveObject.js
Normal file
21
v3/src/input/components/PointWithinInteractiveObject.js
Normal file
|
@ -0,0 +1,21 @@
|
|||
// x/y MUST be translated before being passed to this function, unless the gameObject is guarnateed to
|
||||
// be not rotated or scaled in any way
|
||||
|
||||
var PointWithinInteractiveObject = function (object, x, y)
|
||||
{
|
||||
if (!object.hitArea)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
// Normalize the origin
|
||||
x += object.gameObject.displayOriginX;
|
||||
y += object.gameObject.displayOriginY;
|
||||
|
||||
object.localX = x;
|
||||
object.localY = y;
|
||||
|
||||
return object.hitAreaCallback(object.hitArea, x, y, object);
|
||||
};
|
||||
|
||||
module.exports = PointWithinInteractiveObject;
|
|
@ -7,15 +7,15 @@ var PointerDownEvent = new Class({
|
|||
|
||||
initialize:
|
||||
|
||||
function PointerDownEvent (pointer, gameObject)
|
||||
function PointerDownEvent (pointer, interactiveObject)
|
||||
{
|
||||
Event.call(this, 'POINTER_DOWN_EVENT');
|
||||
|
||||
this.pointer = pointer;
|
||||
this.gameObject = gameObject;
|
||||
this.gameObject = interactiveObject.gameObject;
|
||||
|
||||
// this.x;
|
||||
// this.y;
|
||||
this.x = interactiveObject.localX;
|
||||
this.y = interactiveObject.localY;
|
||||
}
|
||||
|
||||
});
|
||||
|
|
|
@ -7,15 +7,15 @@ var PointerOutEvent = new Class({
|
|||
|
||||
initialize:
|
||||
|
||||
function PointerOutEvent (pointer, gameObject)
|
||||
function PointerOutEvent (pointer, interactiveObject)
|
||||
{
|
||||
Event.call(this, 'POINTER_OUT_EVENT');
|
||||
|
||||
this.pointer = pointer;
|
||||
this.gameObject = gameObject;
|
||||
this.gameObject = interactiveObject.gameObject;
|
||||
|
||||
// this.x;
|
||||
// this.y;
|
||||
this.x = interactiveObject.localX;
|
||||
this.y = interactiveObject.localY;
|
||||
}
|
||||
|
||||
});
|
||||
|
|
|
@ -7,15 +7,15 @@ var PointerOverEvent = new Class({
|
|||
|
||||
initialize:
|
||||
|
||||
function PointerOverEvent (pointer, gameObject)
|
||||
function PointerOverEvent (pointer, interactiveObject)
|
||||
{
|
||||
Event.call(this, 'POINTER_OVER_EVENT');
|
||||
|
||||
this.pointer = pointer;
|
||||
this.gameObject = gameObject;
|
||||
this.gameObject = interactiveObject.gameObject;
|
||||
|
||||
// this.x;
|
||||
// this.y;
|
||||
this.x = interactiveObject.localX;
|
||||
this.y = interactiveObject.localY;
|
||||
}
|
||||
|
||||
});
|
||||
|
|
|
@ -7,15 +7,15 @@ var PointerUpEvent = new Class({
|
|||
|
||||
initialize:
|
||||
|
||||
function PointerUpEvent (pointer, gameObject)
|
||||
function PointerUpEvent (pointer, interactiveObject)
|
||||
{
|
||||
Event.call(this, 'POINTER_UP_EVENT');
|
||||
|
||||
this.pointer = pointer;
|
||||
this.gameObject = gameObject;
|
||||
this.gameObject = interactiveObject.gameObject;
|
||||
|
||||
// this.x;
|
||||
// this.y;
|
||||
this.x = interactiveObject.localX;
|
||||
this.y = interactiveObject.localY;
|
||||
}
|
||||
|
||||
});
|
||||
|
|
|
@ -1,11 +1,12 @@
|
|||
var Class = require('../utils/Class');
|
||||
var InputEvent = require('../input/events');
|
||||
var Rectangle = require('../geom/rectangle/Rectangle');
|
||||
var RectangleContains = require('../geom/rectangle/Contains');
|
||||
var Circle = require('../geom/circle/Circle');
|
||||
var CircleContains = require('../geom/circle/Contains');
|
||||
var Class = require('../utils/Class');
|
||||
var Ellipse = require('../geom/ellipse/Ellipse');
|
||||
var EllipseContains = require('../geom/ellipse/Contains');
|
||||
var InputEvent = require('../input/events');
|
||||
var InteractiveObject = require('../input/InteractiveObject');
|
||||
var Rectangle = require('../geom/rectangle/Rectangle');
|
||||
var RectangleContains = require('../geom/rectangle/Contains');
|
||||
var Triangle = require('../geom/triangle/Triangle');
|
||||
var TriangleContains = require('../geom/triangle/Contains');
|
||||
|
||||
|
@ -40,7 +41,7 @@ var InputManager = new Class({
|
|||
|
||||
this._size = 0;
|
||||
|
||||
// All interactive objects
|
||||
// All list of all Interactive Objects
|
||||
this._list = [];
|
||||
|
||||
// Only those which are currently below a pointer (any pointer)
|
||||
|
@ -234,6 +235,8 @@ var InputManager = new Class({
|
|||
}
|
||||
},
|
||||
|
||||
// Adds a new InteractiveObject to this Input Manager.
|
||||
// Created automatically via methods like setHitArea, or can be created manually.
|
||||
add: function (child)
|
||||
{
|
||||
if (this._pendingInsertion.indexOf(child) === -1 && this._list.indexOf(child) === -1)
|
||||
|
@ -244,6 +247,7 @@ var InputManager = new Class({
|
|||
return this;
|
||||
},
|
||||
|
||||
// Removes an InteractiveObject from this Input Manager.
|
||||
remove: function (child)
|
||||
{
|
||||
this._pendingRemoval.push(child);
|
||||
|
@ -265,7 +269,7 @@ var InputManager = new Class({
|
|||
gameObject[i].hitArea = shape;
|
||||
gameObject[i].hitAreaCallback = callback;
|
||||
|
||||
this.add(gameObject[i]);
|
||||
this.add(InteractiveObject(gameObject[i], shape, callback));
|
||||
}
|
||||
}
|
||||
else
|
||||
|
@ -273,7 +277,7 @@ var InputManager = new Class({
|
|||
gameObject.hitArea = shape;
|
||||
gameObject.hitAreaCallback = callback;
|
||||
|
||||
this.add(gameObject);
|
||||
this.add(InteractiveObject(gameObject, shape, callback));
|
||||
}
|
||||
|
||||
return this;
|
||||
|
@ -297,7 +301,7 @@ var InputManager = new Class({
|
|||
entity.hitArea = new Rectangle(0, 0, entity.frame.width, entity.frame.height);
|
||||
entity.hitAreaCallback = callback;
|
||||
|
||||
this.add(entity);
|
||||
this.add(InteractiveObject(entity, entity.hitArea, callback));
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Reference in a new issue