Skip to content

Add Buttons.None to Buttons.#4618

Closed
BaseCrosser wants to merge 2 commits intoMonoGame:developfrom
BaseCrosser:develop
Closed

Add Buttons.None to Buttons.#4618
BaseCrosser wants to merge 2 commits intoMonoGame:developfrom
BaseCrosser:develop

Conversation

@BaseCrosser
Copy link
Copy Markdown

Issue #4617

@tomspilman
Copy link
Copy Markdown
Member

@KonajuGames @dellis1972 - If you think this is ok... we can merge it after the 3.5 release.

@harry-cpp
Copy link
Copy Markdown
Member

This PR only adds a button, it doesn't actually connect it with the code... It will always be false.

@tomspilman
Copy link
Copy Markdown
Member

My thinking was the intent was for something like:

if (GamePad.GetState().Buttons.Value == Buttons.None)
   ...

But I think what @cra0zy is getting at is that the input API never returns the Buttons state anywhere like this.

I guess it means you can now do new GamePadButtons(Buttons.None) where before you had to do new GamePadButtons(0).

@Tzenchor
Copy link
Copy Markdown
Contributor

Tzenchor commented Mar 8, 2016

This should work through GamePadState.IsButtonDown https://github.com/mono/MonoGame/blob/develop/MonoGame.Framework/Input/GamePadState.cs#L186
I was wrong, that method would always return true

@BaseCrosser
Copy link
Copy Markdown
Author

My intent was to have a empty value in Buttons like there is in Keys.
So that it returns false when you do GamePad.GetState().IsButtonDown(Buttons.None).
I didn't actually test this because I don't have access to my dev computer right now.
If my thinking is wrong, what exactly should be changed to make it work like I imagine?

@Tzenchor
Copy link
Copy Markdown
Contributor

Tzenchor commented Mar 9, 2016

The problem is that GamePad.GetState().IsButtonDown implementation is doing a bitwise & comparison between the pressed buttons and the parameter, but Anything & 0 returns 0, and 0 == 0 is always true

@KonajuGames
Copy link
Copy Markdown
Contributor

It would be a way of removing a key binding without have an accompanying bool to say it has been bound to a button, or having to typecast 0 to a non-existent Buttons enum value.

@KonajuGames
Copy link
Copy Markdown
Contributor

The problem is that GamePad.GetState().IsButtonDown implementation is doing a bitwise & comparison between the pressed buttons and the parameter, but Anything & 0 returns 0, and 0 == 0 is always true

It would need a special case for Buttons.None. This gets a little messy, with potential for adding bugs.

@BaseCrosser
Copy link
Copy Markdown
Author

And what if I just change the value of None to 3. Then it wouldn't be 0 anymore and this should work.
I tested it with this code:

if (GamePad.GetState(PlayerIndex.One).IsButtonDown((Buttons)3))
    Exit();

None of the buttons on the game pad triggered it so I assume it is working then.

Edit: 3 is equal to DpadUp and DpadDown together. Since those 2 can't be triggered at the same time this should work.

@Tzenchor
Copy link
Copy Markdown
Contributor

Tzenchor commented Mar 9, 2016

A "3" are two different buttons at the same time, the ones with value 1 and 2 concretelly.
Also querying GamePad.GetState().IsButtonDown(Buttons.None) will always returns false unless those two buttons are pressed at the same time

@BaseCrosser
Copy link
Copy Markdown
Author

The buttons with value 1 and 2 are DpadUp and DpadDown.
Those 2 can't be pressed at the same time so Buttons.None will always return false just like I intended.
It is as @KonajuGames says a way to remove a key binding.
That is also the reason I am proposing this.

@BaseCrosser
Copy link
Copy Markdown
Author

I will close this now so that somebody else can add it correctly.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants