BlueGit

timfa frameworkv3

fix input clicking

timfa Tim · pushed by timfa

Authored 2022-10-15 · 4 years ago

Hash
8c9dd7f2394583994e983b70fa2b90104c2955f2
Parent
2879d2fc
2 files changed +13 −11
framework/engine/objectComponents/collider.js +9 −7
@@ -10,20 +10,22 @@ class Collider
10 10
11 11 update(deltaTime)
12 12 {
13 if (GameInput.mousePressed())
13 let pressed = GameInput.mousePressed();
14 let held = GameInput.mouseHeld();
15 if (pressed.left || pressed.middle || pressed.right)
14 16 {
15 this.checkClick(true);
17 this.checkClick(true, pressed);
16 18 }
17 19
18 if (GameInput.mouseHeld())
20 if (held.left || held.middle || held.right)
19 21 {
20 this.checkClick(false);
22 this.checkClick(false, held);
21 23 }
22 24
23 25 this.checkCollisions()
24 26 }
25 27
26 checkClick(thisFrame)
28 checkClick(thisFrame, btns)
27 29 {
28 30 var hit = false;
29 31 var clickPos = GameInput.mousePosition.subtract(this.gameObject.scene.position).subtract(this.gameObject.scene.cameraPosition);
@@ -43,11 +45,11 @@ class Collider
43 45 {
44 46 if (thisFrame)
45 47 {
46 this.onClick && this.onClick();
48 this.gameObject.onClick && this.gameObject.onClick(btns);
47 49 }
48 50 else
49 51 {
50 this.onMouseHeld && this.onMouseHeld();
52 this.gameObject.onMouseHeld && this.gameObject.onMouseHeld(btns);
51 53 }
52 54 }
53 55 }
@@ -10,20 +10,22 @@ class Collider
10
10
11 update(deltaTime)
11 update(deltaTime)
12 {
12 {
13 if (GameInput.mousePressed())
13 let pressed = GameInput.mousePressed();
14 let held = GameInput.mouseHeld();
15 if (pressed.left || pressed.middle || pressed.right)
14 {
16 {
15 this.checkClick(true);
17 this.checkClick(true, pressed);
16 }
18 }
17
19
18 if (GameInput.mouseHeld())
20 if (held.left || held.middle || held.right)
19 {
21 {
20 this.checkClick(false);
22 this.checkClick(false, held);
21 }
23 }
22
24
23 this.checkCollisions()
25 this.checkCollisions()
24 }
26 }
25
27
26 checkClick(thisFrame)
28 checkClick(thisFrame, btns)
27 {
29 {
28 var hit = false;
30 var hit = false;
29 var clickPos = GameInput.mousePosition.subtract(this.gameObject.scene.position).subtract(this.gameObject.scene.cameraPosition);
31 var clickPos = GameInput.mousePosition.subtract(this.gameObject.scene.position).subtract(this.gameObject.scene.cameraPosition);
@@ -43,11 +45,11 @@ class Collider
43 {
45 {
44 if (thisFrame)
46 if (thisFrame)
45 {
47 {
46 this.onClick && this.onClick();
48 this.gameObject.onClick && this.gameObject.onClick(btns);
47 }
49 }
48 else
50 else
49 {
51 {
50 this.onMouseHeld && this.onMouseHeld();
52 this.gameObject.onMouseHeld && this.gameObject.onMouseHeld(btns);
51 }
53 }
52 }
54 }
53 }
55 }
framework/util/input.js +4 −4
@@ -72,7 +72,7 @@ var GameInput =
72 72 {
73 73 if(!GameInput.trueMousePosition)
74 74 GameInput.trueMousePosition = new vector();
75
75
76 76 GameInput.trueMousePosition.x = e.x;
77 77 GameInput.trueMousePosition.y = e.y;
78 78 }
@@ -130,7 +130,7 @@ var GameInput =
130 130
131 131 if(GameInput.g_middleMouseDownThisFrame && !GameInput.g_middleMouseDown)
132 132 {
133 GameInput.g_midleMouseDown = true;
133 GameInput.g_middleMouseDown = true;
134 134 }
135 135 },
136 136
@@ -161,7 +161,7 @@ var GameInput =
161 161 case GameInput.MouseButtons.Right: return GameInput.g_altMouseDownThisFrame;
162 162 }
163 163
164 return GameInput.g_mouseDownThisFrame;
164 return {left: GameInput.g_mouseDownThisFrame, middle: GameInput.g_middleMouseDownThisFrame, right: GameInput.g_altMouseDownThisFrame};
165 165 },
166 166
167 167 mouseHeld: function(btn)
@@ -173,6 +173,6 @@ var GameInput =
173 173 case GameInput.MouseButtons.Right: return GameInput.g_altMouseDown;
174 174 }
175 175
176 return GameInput.g_mouseDown;
176 return {left: GameInput.g_mouseDown, middle: GameInput.g_middleMouseDown, right: GameInput.g_altMouseDown};
177 177 }
178 178 }//
@@ -72,7 +72,7 @@ var GameInput =
72 {
72 {
73 if(!GameInput.trueMousePosition)
73 if(!GameInput.trueMousePosition)
74 GameInput.trueMousePosition = new vector();
74 GameInput.trueMousePosition = new vector();
75
75
76 GameInput.trueMousePosition.x = e.x;
76 GameInput.trueMousePosition.x = e.x;
77 GameInput.trueMousePosition.y = e.y;
77 GameInput.trueMousePosition.y = e.y;
78 }
78 }
@@ -130,7 +130,7 @@ var GameInput =
130
130
131 if(GameInput.g_middleMouseDownThisFrame && !GameInput.g_middleMouseDown)
131 if(GameInput.g_middleMouseDownThisFrame && !GameInput.g_middleMouseDown)
132 {
132 {
133 GameInput.g_midleMouseDown = true;
133 GameInput.g_middleMouseDown = true;
134 }
134 }
135 },
135 },
136
136
@@ -161,7 +161,7 @@ var GameInput =
161 case GameInput.MouseButtons.Right: return GameInput.g_altMouseDownThisFrame;
161 case GameInput.MouseButtons.Right: return GameInput.g_altMouseDownThisFrame;
162 }
162 }
163
163
164 return GameInput.g_mouseDownThisFrame;
164 return {left: GameInput.g_mouseDownThisFrame, middle: GameInput.g_middleMouseDownThisFrame, right: GameInput.g_altMouseDownThisFrame};
165 },
165 },
166
166
167 mouseHeld: function(btn)
167 mouseHeld: function(btn)
@@ -173,6 +173,6 @@ var GameInput =
173 case GameInput.MouseButtons.Right: return GameInput.g_altMouseDown;
173 case GameInput.MouseButtons.Right: return GameInput.g_altMouseDown;
174 }
174 }
175
175
176 return GameInput.g_mouseDown;
176 return {left: GameInput.g_mouseDown, middle: GameInput.g_middleMouseDown, right: GameInput.g_altMouseDown};
177 }
177 }
178}//
178}//