mirror of
https://github.com/photonstorm/phaser
synced 2024-11-26 06:30:38 +00:00
Mouse Input Handler working. Demo created.
This commit is contained in:
parent
ca1b483423
commit
b6b7715021
10 changed files with 64 additions and 20 deletions
|
@ -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);
|
||||
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
var CHECKSUM = {
|
||||
build: '907ae780-4d47-11e7-a1ba-9fe9a3b95341'
|
||||
build: 'ef0a8d80-4fc4-11e7-8a79-a19b26898a36'
|
||||
};
|
||||
module.exports = CHECKSUM;
|
|
@ -1,6 +1,7 @@
|
|||
// GlobalInputManager
|
||||
|
||||
var Keyboard = require('./keyboard/KeyboardManager');
|
||||
var Mouse = require('./mouse/MouseManager');
|
||||
|
||||
var GlobalInputManager = function (game, gameConfig)
|
||||
{
|
||||
|
|
|
@ -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];
|
||||
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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);
|
||||
|
|
16
v3/src/input/mouse/events/MouseMoveEvent.js
Normal file
16
v3/src/input/mouse/events/MouseMoveEvent.js
Normal 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;
|
|
@ -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);
|
||||
|
|
|
@ -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')
|
||||
};
|
||||
|
|
7
v3/src/input/mouse/index.js
Normal file
7
v3/src/input/mouse/index.js
Normal file
|
@ -0,0 +1,7 @@
|
|||
// Phaser.Input.Mouse
|
||||
|
||||
module.exports = {
|
||||
|
||||
MouseManager: require('./MouseManager')
|
||||
|
||||
};
|
Loading…
Reference in a new issue