• Hey Guest! Ever feel like entering a Game Jam, but the time limit is always too much pressure? We get it... You lead a hectic life and dedicating 3 whole days to make a game just doesn't work for you! So, why not enter the GMC SLOW JAM? Take your time! Kick back and make your game over 4 months! Interested? Then just click here!

Rotary Spinner Control - Mouse X Movement

meyers980

Member
Hello everyone, I'm still somewhat new to GM Studio 2, only made a couple simple games. I'm now creating a dedicated game for a small project that I'd like to control through a spinner - which is essentially a mouse that only detects X movement.

Up until now, I've only used drag n drop. But I'd be willing to have some code blocks too.

Can someone help me? I've done searching but not found exactly what I want. Essentially, when the mouse X increases by a certain amount, I'd like to jump to a point. And when mouse X decreases by a certain amount, I'd like to jump to another point.

Thanks for any guidance!
 
P

Pyxus

Guest
Hello everyone, I'm still somewhat new to GM Studio 2, only made a couple simple games. I'm now creating a dedicated game for a small project that I'd like to control through a spinner - which is essentially a mouse that only detects X movement.

Up until now, I've only used drag n drop. But I'd be willing to have some code blocks too.

Can someone help me? I've done searching but not found exactly what I want. Essentially, when the mouse X increases by a certain amount, I'd like to jump to a point. And when mouse X decreases by a certain amount, I'd like to jump to another point.

Thanks for any guidance!
Sorry i'm failing to understand what you're asking for, got another game to compare your idea to? or maybe a gif of some sort?
 

meyers980

Member
Sure, something like Breakout or Pong. In those games, when you move the spinner - your paddle moves in the direction you spin.

Same idea for me, except when you move the spinner in my game you'll "jump to a point" in increments. The computer sees the spinner as a mouse with only an X axis. So, ultimately, I just need to tell the game;

When mouse X axis goes up, jump to a point. (50 pixels to the right relative)
When mouse X axis goes down, jump to a point. (50 pixels to the left relative)

Sorry, I hope that's useful. I don't know all the GameMaker terminology so I'm probably describing this poorly.
 
P

Pyxus

Guest
Sure, something like Breakout or Pong. In those games, when you move the spinner - your paddle moves in the direction you spin.

Same idea for me, except when you move the spinner in my game you'll "jump to a point" in increments. The computer sees the spinner as a mouse with only an X axis. So, ultimately, I just need to tell the game;

When mouse X axis goes up, jump to a point. (50 pixels to the right relative)
When mouse X axis goes down, jump to a point. (50 pixels to the left relative)

Sorry, I hope that's useful. I don't know all the GameMaker terminology so I'm probably describing this poorly.
Nah, this isn't a gm terminology thing, just me waking up late and being special. I still don't really know what you mean by "spinner" but I think I get the logic of what you're trying to do. Let me know if I'm still misunderstanding things... but, what you want to do is:
if (mouse x increases) jump to right point.
if (mouse x decreases) jump to left point.
in order to do this you'll need to track what mouse_x was in the previous step. Create a variable called mouse_xprev or something and make it equal to mouse_x in the end step. Once you do that you just need to check how your mouse_x changes by doing if (mouse_x > mouse_xprev) or (mouse_x < mouse_xprev). If mouse_x is greater than the previous mouse_x then the value increased, if less than then it decreased. Then inside of those if check you can run whatever code you want.
If this sounds like what you're trying to do, but you're not too familiar with gml and my explanation is hot garbage let me know and ill try to explain it differently.
 

meyers980

Member
Pyxus, thanks for helping me out! You didn't give me exactly what I needed but put me on the right track by telling me I'd need multiple variables. I use creation code of this:

window_mouse_set(240, 0);
wx = 240;
wxplus = wx + 40;
wxminus = wx - 40;

Then in my stepper I check to see where the mouse is currently with this:

wx = window_mouse_get_x();

If it's larger than wxplus, it moves right. If it's smaller than wxminus, it moves left. Afterwards, I update the variable again with this:

wxminus = wx - 40;
wxplus = wx + 40;

And it's all working exactly as needed! I would post a video of my game in action but it says I need 5 posts before I'm allowed links. And if you're still wondering what a spinner is, Google image search "pong control panel" and I think you'll recognize what I'm talking about. They're the knobs that you turn.
 
P

Pyxus

Guest
Pyxus, thanks for helping me out! You didn't give me exactly what I needed but put me on the right track by telling me I'd need multiple variables. I use creation code of this:

window_mouse_set(240, 0);
wx = 240;
wxplus = wx + 40;
wxminus = wx - 40;

Then in my stepper I check to see where the mouse is currently with this:

wx = window_mouse_get_x();

If it's larger than wxplus, it moves right. If it's smaller than wxminus, it moves left. Afterwards, I update the variable again with this:

wxminus = wx - 40;
wxplus = wx + 40;

And it's all working exactly as needed! I would post a video of my game in action but it says I need 5 posts before I'm allowed links. And if you're still wondering what a spinner is, Google image search "pong control panel" and I think you'll recognize what I'm talking about. They're the knobs that you turn.
Im upset... I do know exactly what you're talking about but was so distracted by the word spinner I kept envisioning a fidget spinner for some reason. Anyway, I'm glad I could if only ever so slightly.
 
Top