Mouse Input Handler working. Demo created.

This commit is contained in:
Richard Davey 2017-06-13 00:38:48 +01:00
parent ca1b483423
commit b6b7715021
10 changed files with 64 additions and 20 deletions

View file

@ -50,6 +50,9 @@ var Config = function (config)
this.inputKeyboard = GetValue(config, 'input.keyboard', true);
this.inputKeyboardEventTarget = GetValue(config, 'input.keyboard.target', window);
this.inputMouse = GetValue(config, 'input.mouse', true);
this.inputMouseEventTarget = GetValue(config, 'input.mouse.target', null);
// If you do: { banner: false } it won't display any banner at all
this.hideBanner = (GetValue(config, 'banner', null) === false);

View file

@ -1,4 +1,4 @@
var CHECKSUM = {
build: '907ae780-4d47-11e7-a1ba-9fe9a3b95341'
build: 'ef0a8d80-4fc4-11e7-8a79-a19b26898a36'
};
module.exports = CHECKSUM;

View file

@ -1,6 +1,7 @@
// GlobalInputManager
var Keyboard = require('./keyboard/KeyboardManager');
var Mouse = require('./mouse/MouseManager');
var GlobalInputManager = function (game, gameConfig)
{

View file

@ -214,20 +214,22 @@ KeyboardManager.prototype = {
update: function ()
{
if (!this.enabled)
var len = this.queue.length;
if (!this.enabled || len === 0)
{
return;
}
// Clears the queue array, and also means we don't work on array data that could potentially
// be modified during the processing phase
var queue = this.queue.splice(0, this.queue.length);
var queue = this.queue.splice(0, len);
var keys = this.keys;
var singleKey;
// Process the event queue, dispatching all of the events that have stored up
for (var i = 0; i < queue.length; i++)
for (var i = 0; i < len; i++)
{
var event = queue[i];

View file

@ -35,6 +35,11 @@ MouseManager.prototype = {
this.enabled = config.inputMouse;
this.target = config.inputMouseEventTarget;
if (!this.target)
{
this.target = this.manager.game.canvas;
}
if (this.enabled)
{
this.startListeners();
@ -44,7 +49,6 @@ MouseManager.prototype = {
startListeners: function ()
{
var queue = this.queue;
// var captures = this.captures;
var mouseHandler = function (event)
{
@ -55,11 +59,6 @@ MouseManager.prototype = {
}
queue.push(event);
// if (captures[event.keyCode])
// {
// event.preventDefault();
// }
};
this.mouseHandler = mouseHandler;
@ -77,30 +76,39 @@ MouseManager.prototype = {
},
// https://developer.mozilla.org/en-US/docs/Web/API/MouseEvent
// https://github.com/WICG/EventListenerOptions/blob/gh-pages/explainer.md
update: function ()
{
if (!this.enabled)
var len = this.queue.length;
if (!this.enabled || len === 0)
{
return;
}
// Clears the queue array, and also means we don't work on array data that could potentially
// be modified during the processing phase
var queue = this.queue.splice(0, this.queue.length);
var queue = this.queue.splice(0, len);
// Process the event queue, dispatching all of the events that have stored up
for (var i = 0; i < queue.length; i++)
for (var i = 0; i < len; i++)
{
var event = queue[i];
if (event.type === 'mousedown')
switch (event.type)
{
case 'mousemove':
this.events.dispatch(new Event.MOUSE_MOVE_EVENT(event));
break;
case 'mousedown':
this.events.dispatch(new Event.MOUSE_DOWN_EVENT(event));
}
else if (event.type === 'mouseup')
{
break;
case 'mouseup':
this.events.dispatch(new Event.MOUSE_UP_EVENT(event));
break;
}
}
}

View file

@ -5,6 +5,9 @@ var MouseDownEvent = function (nativeEvent)
Event.call(this, 'MOUSE_DOWN_EVENT');
this.data = nativeEvent;
this.x = nativeEvent.clientX;
this.y = nativeEvent.clientY;
};
MouseDownEvent.prototype = Object.create(Event.prototype);

View file

@ -0,0 +1,16 @@
var Event = require('../../../events/Event');
var MouseMoveEvent = function (nativeEvent)
{
Event.call(this, 'MOUSE_MOVE_EVENT');
this.data = nativeEvent;
this.x = nativeEvent.clientX;
this.y = nativeEvent.clientY;
};
MouseMoveEvent.prototype = Object.create(Event.prototype);
MouseMoveEvent.prototype.constructor = MouseMoveEvent;
module.exports = MouseMoveEvent;

View file

@ -5,6 +5,9 @@ var MouseUpEvent = function (nativeEvent)
Event.call(this, 'MOUSE_UP_EVENT');
this.data = nativeEvent;
this.x = nativeEvent.clientX;
this.y = nativeEvent.clientY;
};
MouseUpEvent.prototype = Object.create(Event.prototype);

View file

@ -1,5 +1,6 @@
module.exports = {
MOUSE_DOWN_EVENT: require('./MouseDownEvent'),
MOUSE_UP_EVENT: require('./MouseUpEvent')
MOUSE_UP_EVENT: require('./MouseUpEvent'),
MOUSE_MOVE_EVENT: require('./MouseMoveEvent')
};

View file

@ -0,0 +1,7 @@
// Phaser.Input.Mouse
module.exports = {
MouseManager: require('./MouseManager')
};