-
Notifications
You must be signed in to change notification settings - Fork 41
/
Copy pathUICursor.js
72 lines (58 loc) · 1.83 KB
/
UICursor.js
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
/**
* Created by Jerome on 29-11-17.
*/
import CustomSprite from './CustomSprite';
import UI from './UI';
const UICursor = new Phaser.Class({
Extends: CustomSprite,
initialize: function UICursor() {
CustomSprite.call(this, 'UI', UI.getGameWidth()/2, UI.getGameHeight()/2, 'cursors','cursor');
this.setDepth(25);
this.setOrigin(0,0);
this.cursorFrames = {
default: 'cursor',
bomb: 'bombcursor',
bow: 'bow',
building: 'door',
combat: 'sabre',
gun: 'gun',
item: 'hand',
melee: 'melee',
move: 'movement'
};
// List of cursors that change appearance when the mouse is pressed
this.dualCursors = ['move', 'item', 'building', 'combat', 'melee', 'bow', 'gun'];
this.currentFrame = 'cursor'; // current frame displayed, regardless of pressed or not
},
updatePosition: function(x, y){
this.setPosition(
x,
y
);
},
changeCursor: function(cursor){
var frameKey = cursor || 'default';
this.setFrame(this.cursorFrames[frameKey]);
this.currentFrame = frameKey;
},
/**
* Called when releasing the click
*/
up: function(){
if(this.dualCursors.includes(this.currentFrame)) this.setFrame(this.cursorFrames[this.currentFrame]);
},
/**
* Called when clicking; if the currently displayed cursor has a 'pressed' frame (ending in 2 in the frame names),
* then display it
*/
down: function(){
if(this.dualCursors.includes(this.currentFrame)) this.setFrame(this.cursorFrames[this.currentFrame]+'2');
},
display: function () {
this.setVisible(true);
},
hide: function () {
this.setVisible(false);
}
});
export default UICursor;