forked from phaserjs/phaser
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathSceneInputManager.js
More file actions
180 lines (134 loc) · 5.86 KB
/
Copy pathSceneInputManager.js
File metadata and controls
180 lines (134 loc) · 5.86 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
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
var Class = require('../../utils/Class');
var EventEmitter = require('eventemitter3');
// Drag Events
// https://developer.mozilla.org/en-US/docs/Web/API/HTML_Drag_and_Drop_API
// Mouse Events
// https://developer.mozilla.org/en-US/docs/Web/API/MouseEvent
var SceneInputManager = new Class({
Extends: EventEmitter,
initialize:
function SceneInputManager (scene)
{
EventEmitter.call(this);
// The Scene that owns this plugin
this.scene = scene;
// GlobalInputManager
this.manager = scene.sys.game.input;
// A reference to this.scene.sys.displayList (set in boot)
this.displayList;
// A reference to the this.scene.sys.cameras (set in boot)
this.cameras;
// Proxy references available via the Scene
this.keyboard = this.manager.keyboard;
this.mouse = this.manager.mouse;
this.gamepad = this.manager.gamepad;
// Only fire callbacks and events on the top-most Game Object in the display list (emulating DOM behavior)
// and ignore any GOs below it, or call them all?
this.topOnly = true;
// How often should the pointer input be checked?
// Time given in ms
// Pointer will *always* be checked if it has been moved by the user.
// This controls how often it will be polled if it hasn't been moved.
// Set to 0 to poll constantly. Set to -1 to only poll on user movement.
this.pollRate = -1;
// Internal counter
this._pollTimer = 0;
// The distance, in pixels, the pointer has to move while being held down, before it thinks it is being dragged.
this.dragDistanceThreshold = 0;
// The amount of time, in ms, the pointer has to be held down before it thinks it is dragging.
this.dragTimeThreshold = 0;
// Used to temporarily store the results of the Hit Test
this._temp = [];
// list: A list of all Game Objects that have been set to be interactive
this._list = [];
// pendingInsertion: Objects waiting to be inserted to the list on the next call to 'begin'
this._pendingInsertion = [];
// pendingRemoval: Objects waiting to be removed from the list on the next call to 'begin'
this._pendingRemoval = [];
// draggable: A list of all Game Objects that have been enabled for dragging
this._draggable = [];
// drag: A list of all Interactive Objects currently considered as being 'draggable' by any pointer, indexed by pointer ID
this._drag = { 0: [], 1: [], 2: [], 3: [], 4: [], 5: [], 6: [], 7: [], 8: [], 9: [] };
// over: A list of all Interactive Objects currently considered as being 'over' by any pointer, indexed by pointer ID
this._over = { 0: [], 1: [], 2: [], 3: [], 4: [], 5: [], 6: [], 7: [], 8: [], 9: [] };
this._validTypes = [ 'onDown', 'onUp', 'onOver', 'onOut', 'onMove', 'onDragStart', 'onDrag', 'onDragEnd', 'onDragEnter', 'onDragLeave', 'onDragOver', 'onDrop' ];
},
// Add option to get all IOs within a Rect or Circle
boot: require('./inc/Boot'),
begin: require('./inc/Begin'),
clear: require('./inc/Clear'),
update: require('./inc/Update'),
hitTestPointer: require('./inc/HitTestPointer'),
disable: require('./inc/Disable'),
enable: require('./inc/Enable'),
queueForInsertion: require('./inc/QueueForInsertion'),
queueForRemoval: require('./inc/QueueForRemoval'),
setPollRate: require('./inc/SetPollRate'),
setPollAlways: require('./inc/SetPollAlways'),
setPollOnMove: require('./inc/SetPollOnMove'),
setTopOnly: require('./inc/SetTopOnly'),
setHitArea: require('./inc/SetHitArea'),
setHitAreaCircle: require('./inc/SetHitAreaCircle'),
setHitAreaEllipse: require('./inc/SetHitAreaEllipse'),
setHitAreaFromTexture: require('./inc/SetHitAreaFromTexture'),
setHitAreaRectangle: require('./inc/SetHitAreaRectangle'),
setHitAreaTriangle: require('./inc/SetHitAreaTriangle'),
setDraggable: require('./inc/SetDraggable'),
processOverOutEvents: require('./inc/ProcessOverOutEvents'),
processDownEvents: require('./inc/ProcessDownEvents'),
processDragEvents: require('./inc/ProcessDragEvents'),
processUpEvents: require('./inc/ProcessUpEvents'),
processMoveEvents: require('./inc/ProcessMoveEvents'),
sortGameObjects: require('./inc/SortGameObjects'),
sortInteractiveObjects: require('./inc/SortInteractiveObjects'),
sortHandlerGO: require('./inc/SortHandlerGO'),
sortHandlerIO: require('./inc/SortHandlerIO'),
activePointer: {
get: function ()
{
return this.manager.activePointer;
}
},
// The x/y coordinates of the ActivePointer based on the first camera in the camera list.
// This is only safe to use if your game has just 1 non-transformed camera and doesn't use multi-touch.
x: {
get: function ()
{
return this.manager.activePointer.x;
}
},
y: {
get: function ()
{
return this.manager.activePointer.y;
}
},
// Scene that owns this is shutting down
shutdown: function ()
{
this._temp.length = 0;
this._list.length = 0;
this._draggable.length = 0;
this._pendingRemoval.length = 0;
this._pendingInsertion.length = 0;
for (var i = 0; i < 10; i++)
{
this._drag[i] = [];
this._over[i] = [];
}
this.removeAllListeners();
},
// Game level nuke
destroy: function ()
{
this.shutdown();
this.scene = undefined;
this.cameras = undefined;
this.manager = undefined;
this.events = undefined;
this.keyboard = undefined;
this.mouse = undefined;
this.gamepad = undefined;
}
});
module.exports = SceneInputManager;