Added onMove callback and event. Added processMove handler.

This commit is contained in:
photonstorm 2017-07-21 13:59:22 +01:00
parent fdf257d9ce
commit 1cc79a3b23
11 changed files with 127 additions and 48 deletions

View file

@ -1,4 +1,4 @@
var CHECKSUM = {
build: '2ba7f500-6dc2-11e7-a19b-db1919761fe1'
build: '5f8d0c50-6e14-11e7-a21a-f9e8835d9646'
};
module.exports = CHECKSUM;

View file

@ -22,14 +22,14 @@ var InteractiveObject = function (gameObject, hitArea, hitAreaCallback)
callbackContext: gameObject,
dragX: 0,
dragY: 0,
onMove: NOOP,
onDown: NOOP,
onUp: NOOP,
onOver: NOOP,
onOut: NOOP,
dragX: 0,
dragY: 0,
onDragStart: NOOP,
onDrag: NOOP,
onDragEnd: NOOP

View file

@ -59,7 +59,7 @@ var SceneInputManager = new Class({
down: { 0: [], 1: [], 2: [], 3: [], 4: [], 5: [], 6: [], 7: [], 8: [], 9: [] }
};
this._validTypes = [ 'onDown', 'onUp', 'onOver', 'onOut' ];
this._validTypes = [ 'onDown', 'onUp', 'onOver', 'onOut', 'onMove' ];
},
// Add option to get all IOs within a Rect or Circle
@ -90,6 +90,7 @@ var SceneInputManager = new Class({
setOnOutCallback: require('./components/SetOnOutCallback'),
setOnOverCallback: require('./components/SetOnOverCallback'),
setOnUpCallback: require('./components/SetOnUpCallback'),
setOnMoveCallback: require('./components/SetOnMoveCallback'),
processOverOutEvents: require('./components/ProcessOverOutEvents'),
processDownEvents: require('./components/ProcessDownEvents'),

View file

@ -0,0 +1,54 @@
var InputEvent = require('../events');
var ProcessMoveEvents = function (pointer, currentlyOver)
{
if (currentlyOver.length === 0)
{
// Dispatch MOVE event, even though pointer isn't over anything
this.events.dispatch(new InputEvent.MOVE(pointer));
}
else
{
// Go through all objects the pointer is over and dispatch them
for (var i = 0; i < currentlyOver.length; i++)
{
var interactiveObject = currentlyOver[i];
this.events.dispatch(new InputEvent.MOVE(pointer, interactiveObject.gameObject, currentlyOver));
this.childOnMove(pointer, interactiveObject);
if (this.topOnly)
{
break;
}
}
}
// Check the list of Draggable Items
/*
for (var i = 0; i < this.children.draggable.length; i++)
{
var interactiveObject = this.children.draggable[i];
if (!interactiveObject.enabled)
{
continue;
}
if (pointer.justUp && interactiveObject.isDragged)
{
// Drag End
this.childOnDragEnd(i, pointer, interactiveObject);
}
else if (interactiveObject.isDragged)
{
// Drag
this.childOnDrag(i, pointer, interactiveObject);
}
}
*/
};
module.exports = ProcessMoveEvents;

View file

@ -25,7 +25,7 @@ var ProcessOverOutEvents = function (pointer, currentlyOver)
// In the currentlyOver array
stillOver.push(interactiveObject);
}
};
}
// Go through the hit test results
for (i = 0; i < currentlyOver.length; i++)

View file

@ -1,5 +1,14 @@
var SetCallbacks = function (gameObjects, onDown, onUp, onOver, onOut, context)
var GetFastValue = require('../../../utils/object/GetFastValue');
var SetCallbacks = function (gameObjects, config)
{
var onDown = GetFastValue(config, 'onDown', null);
var onUp = GetFastValue(config, 'onUp', null);
var onOver = GetFastValue(config, 'onOver', null);
var onOut = GetFastValue(config, 'onOut', null);
var onMove = GetFastValue(config, 'onMove', null);
var context = GetFastValue(config, 'context', null);
if (onDown)
{
this.setOnDownCallback(gameObjects, onDown, context);
@ -20,6 +29,11 @@ var SetCallbacks = function (gameObjects, onDown, onUp, onOver, onOut, context)
this.setOnDownCallback(gameObjects, onOut, context);
}
if (onMove)
{
this.setOnMoveCallback(gameObjects, onMove, context);
}
return this;
};

View file

@ -0,0 +1,6 @@
var SetOnMoveCallback = function (gameObjects, callback, context)
{
return this.setCallback(gameObjects, 'onMove', callback, context);
};
module.exports = SetOnMoveCallback;

View file

@ -56,10 +56,10 @@ var Update = function (time, delta)
this.processDownEvents(pointer, results);
}
// if (pointer.justMoved)
// {
// this.processMovementEvents(pointer, results);
// }
if (pointer.justMoved)
{
this.processMoveEvents(pointer, results);
}
}
};

View file

@ -0,0 +1,28 @@
var Class = require('../../../utils/Class');
var Event = require('../../../events/Event');
var PointerMoveEvent = new Class({
Extends: Event,
initialize:
function PointerMoveEvent (pointer, topObject, gameObjects)
{
Event.call(this, 'POINTER_MOVE_EVENT');
this.pointer = pointer;
this.x = pointer.x;
this.y = pointer.y;
// An array of all the game objects the pointer event occurred on
this.list = gameObjects;
// A reference to the top-most game object in the list (based on display list order)
this.gameObject = topObject;
}
});
module.exports = PointerMoveEvent;

View file

@ -6,6 +6,7 @@ module.exports = {
DRAG: require('./DragEvent'),
DRAG_END: require('./DragEndEvent'),
DRAG_START: require('./DragStartEvent'),
MOVE: require('./PointerMoveEvent'),
OUT: require('./PointerOutEvent'),
OVER: require('./PointerOverEvent'),
UP: require('./PointerUpEvent')

View file

@ -13,56 +13,32 @@ var InputManager = new Class({
SceneInputManager.call(this, scene, game);
},
childOnMove: function (pointer, interactiveObject)
{
interactiveObject.onMove(interactiveObject.gameObject, pointer);
}
/*
// Has the pointer moved in this update?
processMovementEvents: function (pointer)
childOnDragStart: function (index, pointer, interactiveObject)
{
// Check the list of Draggable Items
for (var i = 0; i < this._draggable.length; i++)
{
var gameObject = this._draggable[i];
var input = gameObject.input;
interactiveObject.isDragged = true;
if (!input.enabled)
{
continue;
}
if (pointer.justUp && input.isDragged)
{
// Drag End
this.gameObjectOnDragEnd(pointer, gameObject);
}
else if (input.isDragged)
{
// Drag
this.gameObjectOnDrag(pointer, gameObject);
}
}
},
gameObjectOnDragStart: function (pointer, gameObject)
{
var input = gameObject.input;
input.isDragged = true;
input.dragX = input.localX - gameObject.displayOriginX;
input.dragY = input.localY - gameObject.displayOriginY;
interactiveObject.dragX = interactiveObject.localX - interactiveObject.gameObject.displayOriginX;
interactiveObject.dragY = interactiveObject.localY - interactiveObject.gameObject.displayOriginY;
this.events.dispatch(new InputEvent.DRAG_START(pointer, gameObject));
gameObject.input.onDragStart(gameObject, pointer);
},
gameObjectOnDrag: function (pointer, gameObject)
childOnDrag: function (index, pointer, interactiveObject)
{
this.events.dispatch(new InputEvent.DRAG(pointer, gameObject));
gameObject.input.onDrag(gameObject, pointer);
},
gameObjectOnDragEnd: function (pointer, gameObject)
childOnDragEnd: function (index, pointer, interactiveObject)
{
var input = gameObject.input;
@ -73,7 +49,6 @@ var InputManager = new Class({
gameObject.input.onDragEnd(gameObject, pointer);
},
*/
});
module.exports = InputManager;