forked from phaserjs/phaser
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathGlobalInputManager.js
More file actions
106 lines (82 loc) · 2.87 KB
/
Copy pathGlobalInputManager.js
File metadata and controls
106 lines (82 loc) · 2.87 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
// GlobalInputManager
var Class = require('../utils/Class');
var EventDispatcher = require('../events/EventDispatcher');
var GetTransformedPoint = require('./components/GetTransformedPoint');
var Keyboard = require('./keyboard/KeyboardManager');
var Mouse = require('./mouse/MouseManager');
var MouseEvent = require('./mouse/events/');
var PointWithinGameObject = require('./components/PointWithinGameObject');
var TransformMatrix = require('../gameobjects/components/TransformMatrix');
var PointScreenToWorldHitTest = require('./components/PointScreenToWorldHitTest');
var GlobalInputManager = new Class({
initialize:
function GlobalInputManager (game, config)
{
this.game = game;
this.config = config;
this.enabled = true;
this.events = new EventDispatcher();
// Standard FIFO queue
this.queue = [];
// Listeners
this.keyboard = new Keyboard(this);
this.mouse = new Mouse(this);
this._tempMatrix = new TransformMatrix();
this._tempPoint = { x: 0, y: 0 };
this._tempHitTest = [];
},
/**
* The Boot handler is called by Phaser.Game when it first starts up.
* The renderer is available by now.
*
* @method Phaser.Input.KeyboardManager#boot
* @private
*/
boot: function ()
{
this.keyboard.boot();
this.mouse.boot();
},
update: function ()
{
this.keyboard.update();
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, len);
// Process the event queue, dispatching all of the events that have stored up
for (var i = 0; i < len; i++)
{
var event = queue[i];
switch (event.type)
{
case 'mousemove':
this.events.dispatch(new MouseEvent.MOVE(event));
break;
case 'mousedown':
this.events.dispatch(new MouseEvent.DOWN(event));
break;
case 'mouseup':
this.events.dispatch(new MouseEvent.UP(event));
break;
}
}
},
getTransformedPoint: function (gameObject, x, y)
{
return GetTransformedPoint(this._tempMatrix, gameObject, x, y, this._tempPoint);
},
pointWithinGameObject: function (gameObject, x, y)
{
return PointWithinGameObject(gameObject, x, y);
},
pointScreenToWorldHitTest: function (gameObjects, x, y, camera)
{
return PointScreenToWorldHitTest(this._tempMatrix, x, y, gameObjects, camera, this._tempHitTest);
}
});
module.exports = GlobalInputManager;