Professional controls/binding scheme
- Taehl
- Dreaming in associative arrays
- Posts: 1025
- Joined: Mon Jan 11, 2010 5:07 am
- Location: CA, USA
- Contact:
Professional controls/binding scheme
I've noticed that nearly all professional computer games offer the same scheme for binding controls: 2 sets of keys and an optional joystick, all configurable. Since I needed to overhaul Underlife's controls anyway, I thought I'd figure out how to recreate that scheme in Love. It ended up just being 33 lines of simple code (and allows both digital and analogue movement). Here's the resulting article: Professional controls
Earliest Love2D supporter who can't Love anymore. Let me disable pixel shaders if I don't use them, dammit!
Lenovo Thinkpad X60 Tablet, built like a tank. But not fancy enough for Love2D 0.10.0+.
Lenovo Thinkpad X60 Tablet, built like a tank. But not fancy enough for Love2D 0.10.0+.
- Robin
- The Omniscient
- Posts: 6506
- Joined: Fri Feb 20, 2009 4:29 pm
- Location: The Netherlands
- Contact:
Re: Professional controls/binding scheme
Ehm, I have some problems with that. It is nice in principle, but things like:
are problematic. You see, once you press "jump" or whatever, it will stick. control["jump"] will become true, and if you release the key, you get control["jump"] = control["jump"] or false. And since control["jump"] was true, it remains true (true or false is true).
It also has some namespace pollution, which is a shame.
Lastly, the examples don't work: you forgot the function keyword as well as leaving out control.update().
Code: Select all
for k,v in pairs(control.keys) do control[k] = control[k] or love.keyboard.isDown(v) end
for k,v in pairs(control.keys2) do control[k] = control[k] or love.keyboard.isDown(v) end
It also has some namespace pollution, which is a shame.
Lastly, the examples don't work: you forgot the function keyword as well as leaving out control.update().
Help us help you: attach a .love.
- Taehl
- Dreaming in associative arrays
- Posts: 1025
- Joined: Mon Jan 11, 2010 5:07 am
- Location: CA, USA
- Contact:
Re: Professional controls/binding scheme
It doesn't stick since the controls are reset to false at the beginning of each control.update(). It has potential namespace pollution since this is just an example which is meant to be tailored to a given game, not a standalone library. As for the examples: You're right, I forgot that. I'll fix it now.
Earliest Love2D supporter who can't Love anymore. Let me disable pixel shaders if I don't use them, dammit!
Lenovo Thinkpad X60 Tablet, built like a tank. But not fancy enough for Love2D 0.10.0+.
Lenovo Thinkpad X60 Tablet, built like a tank. But not fancy enough for Love2D 0.10.0+.
- Robin
- The Omniscient
- Posts: 6506
- Joined: Fri Feb 20, 2009 4:29 pm
- Location: The Netherlands
- Contact:
Re: Professional controls/binding scheme
Oh, you're right, I didn't see that. Still ugly, since you'd need to change that in two places when you add controls.Taehl wrote:It doesn't stick since the controls are reset to false at the beginning of each control.update().
I mean, you can't call a control keys, keys, joyaxes, joybtns or update. That's pretty arbitrary. And so easy and quick to fix.Taehl wrote:It has potential namespace pollution since this is just an example which is meant to be tailored to a given game, not a standalone library.
Help us help you: attach a .love.
Re: Professional controls/binding scheme
It would be nice to have something likeTaehl wrote:It doesn't stick since the controls are reset to false at the beginning of each control.update(). It has potential namespace pollution since this is just an example which is meant to be tailored to a given game, not a standalone library. As for the examples: You're right, I forgot that. I'll fix it now.
SetBinding("KEY_PRESSED", "w", JumpOrFly)
- Taehl
- Dreaming in associative arrays
- Posts: 1025
- Joined: Mon Jan 11, 2010 5:07 am
- Location: CA, USA
- Contact:
Re: Professional controls/binding scheme
Sure I can. In my mind, a control is a thing a game system looks for ("jump", "run", "left"). An input is a hardware signal ("shift", "joybutton 0", "mouse coordinate"). Bindings links input(s) to control(s).Robin wrote:I mean, you can't call a control keys, keys, joyaxes, joybtns or update. That's pretty arbitrary. And so easy and quick to fix.
You could add such a function to my scheme with just a few lines of code. But I would much rather use control.key.JumpOrFly = "w".kraftman wrote:SetBinding("KEY_PRESSED", "w", JumpOrFly)
Earliest Love2D supporter who can't Love anymore. Let me disable pixel shaders if I don't use them, dammit!
Lenovo Thinkpad X60 Tablet, built like a tank. But not fancy enough for Love2D 0.10.0+.
Lenovo Thinkpad X60 Tablet, built like a tank. But not fancy enough for Love2D 0.10.0+.
- Robin
- The Omniscient
- Posts: 6506
- Joined: Fri Feb 20, 2009 4:29 pm
- Location: The Netherlands
- Contact:
Re: Professional controls/binding scheme
No, you don't understand. What I mean is, that you can't call a control "keys" or "update" or those other things. Because control["keys"] and control["update"] are already taken.Taehl wrote:Sure I can. In my mind, a control is a thing a game system looks for ("jump", "run", "left"). An input is a hardware signal ("shift", "joybutton 0", "mouse coordinate"). Bindings links input(s) to control(s).
Modifying it to what it says below this line causes it to crash and burn.
Code: Select all
keys = { up="w", left="a", down="s", right="d", jump=" ", attack="lctrl", menu="escape", update="u" },
Help us help you: attach a .love.
- Taehl
- Dreaming in associative arrays
- Posts: 1025
- Joined: Mon Jan 11, 2010 5:07 am
- Location: CA, USA
- Contact:
Re: Professional controls/binding scheme
You can break /anything/ by changing a line the wrong way. Just don't do that.
Earliest Love2D supporter who can't Love anymore. Let me disable pixel shaders if I don't use them, dammit!
Lenovo Thinkpad X60 Tablet, built like a tank. But not fancy enough for Love2D 0.10.0+.
Lenovo Thinkpad X60 Tablet, built like a tank. But not fancy enough for Love2D 0.10.0+.
- Robin
- The Omniscient
- Posts: 6506
- Joined: Fri Feb 20, 2009 4:29 pm
- Location: The Netherlands
- Contact:
Re: Professional controls/binding scheme
The wrong way, yes. There was nothing wrong about my example.Taehl wrote:You can break /anything/ by changing a line the wrong way. Just don't do that.
Help us help you: attach a .love.
Re: Professional controls/binding scheme
There isn't really a big problem in what our TC is doing, but calling this "professional" seems like a bit too much when it has such relatively simple issues.
My game called Hat Cat and the Obvious Crimes Against the Fundamental Laws of Physics is out now!
Who is online
Users browsing this forum: No registered users and 9 guests