 dekon_17 Registered User |
Quote
|
2022-07-30 23:01:03 |
|
I am trying to create a pretty customizable controls for my game. So far, it goes way better than I thought it would. However, there is one thing that kinda worrying me about how good it is made. Since I want to make controlls customizable to the point that you can bind mouse wheel to particular actions (controls), one thing makes some "problems" - mouse wheel handling. There is no "mouse wheel up" or "mouse wheel down", there is only "mouse wheel moved". I found the solution for that pretty easily, but now... I think it isn't really a good way of doing so (because of optimisation reasons). Here is how it implemented:
... if (this.BootUp == true) { // CV means "Control Variable". // It stores ID of a key or mouse event.
this.Next = ccbGetCopperCubeVariable (this.CV_Next); this.Prev = ccbGetCopperCubeVariable (this.CV_Prev);
if (this.Next == 1) this.NDelta = ccbGetCopperCubeVariable (this.CV_Next + ".dir"); if (this.Prev == 1) this.PDelta = ccbGetCopperCubeVariable (this.CV_Prev + ".dir");
// variable with ".dir" at the end stores wheel direction. // It can only be equal 1 or -1.
this.BootUp = false; } ...
This is where controls are being set for my weapons switch menu script. And there... There is how I made its handling:
behavior_BSGswitch.prototype.onMouseEvent = function (mouseEvent, mouseWheelDelta) { if (mouseEvent == this.Next && this.Next == 1) { // If mouse wheel delta and required delta are both negative or both positive, // the result will only be positive, or, in other words, higher than 0. // And that means that directions match to eachother.
if (mouseWheelDelta / this.NDelta > 0) this.Dir = 1; }
else if (mouseEvent == this.Next && this.Next != 1) this.Dir = 1;
if (mouseEvent == this.Prev && this.Prev == 1) { if (mouseWheelDelta / this.PDelta > 0) this.Dir = -1; }
else if (mouseEvent == this.Prev && this.Prev != 1) this.Dir = -1; }
What makes me concerned here is that it probably becomes a bit... "Heavy"? I mean, I came to this solution in about 5 or 10 minutes, so, I don't think it is the best optimized one. Any thoughts about that? Or, possibly... any optimizations?
|
 Aiming_bullets Guest |
Quote
|
2022-08-01 17:25:45 |
|
there is mousewheeldelta in BEHAVIORS I think, you should ask @robo, @just_in_case or @samMhmdy or maybe to @hadoken, they might know about the mouse delta, there is a behavior zoom with mouse wheel. you can check that to create mousewheel mechanism.
|
 dekon_17 Registered User |
Quote
|
2022-08-01 22:29:41 |
|
No, I mean, I know about this "Delta". The thing is, it needs to be checked ONLY if the control is being bound to mouse wheel. What I've made in there is a big pile of code, and as I think, it won't be optimized very well (especially if it comes to character controller, which has 5 different controls, so, this is going to be a terrible solution).
|