Skip to content

Virtual Gamepad for Platformer2D#15

Merged
tomspilman merged 11 commits intoMonoGame:developfrom
danzel:virtual-gamepad
May 18, 2014
Merged

Virtual Gamepad for Platformer2D#15
tomspilman merged 11 commits intoMonoGame:developfrom
danzel:virtual-gamepad

Conversation

@danzel
Copy link
Contributor

@danzel danzel commented May 4, 2014

Implemented a simple virtual gamepad for the Platformer2D sample.
image

Tested on Android, iPhone, WP8.

Fixes #10

@danzel
Copy link
Contributor Author

danzel commented May 4, 2014

Note I've gone with a minimal implementation just suiting this example.
If we want the full on one that was previously GamePad.Android/iOS I can pull that one over instead.

@tomspilman
Copy link
Member

My first impression from the screenshot is that the UI for this covers the gameplay.

Can we do something a little better? Like maybe fade out the UI rendering after a second or once they start using the controls?

@DDReaper - Thoughts?

@SimonDarksideJ
Copy link
Contributor

That was my first thought also, the controls are way to big on screen constantly.
The SpaceWar sample uses a thumbstick style implementation that is is placed out of the gameplay so it's not too bad (although the on screen visualisation does need scaling to the screen)

For this style of control it's wither going to need a loading screen or as @tomspilman says, it needs to fade out one play has started.
Alternatively, the controls should just use vertical regions instead of just buttons, as the player should be able to press anywhere in the first 1/4 of the screen for left, next qurater right, a 1/4 deadzone and the last quarter for jump. Saw this used in a game called "Reaper" and it seemed to work very well.

@danzel
Copy link
Contributor Author

danzel commented May 4, 2014

Agreed. Will go for fading out after they've been pressed.

@danzel
Copy link
Contributor Author

danzel commented May 5, 2014

Okay, controls fade out after a successful touch. They fade back in after 4 seconds of no touching.

@tomspilman
Copy link
Member

@DDReaper - Want to give this a try before merging?

@danzel
Copy link
Contributor Author

danzel commented May 5, 2014

Happy to do any more work as required. But as you put your fingers over the player for the most part it hard to make this super great on touch :)

@tomspilman
Copy link
Member

Yea... the game isn't really designed for mobile. I'm just letting @DDReaper make the call on this.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This should be part of the HandleInput function, not seperate

@SimonDarksideJ
Copy link
Contributor

Looks good, made one comment about the change to Update. SHould be part of HandleInput.

Also on Windows8 you are currently unable to use the new virtual gamepad. This would be a major limitation on the vast array of touch screen Windows 8 hardware.

Is it possible to consume the gamepad implementation behind the Virtual Gamepad so that both can still be used?

Might be better to have the virtual gamepad on my default and just disable it for non touch platforms such as Ouya, Mac and Linux. Rather than the selective platform do if !Ouya && !Mac etc.

All in all very clean though and with those updates it would be great.

@danzel
Copy link
Contributor Author

danzel commented May 5, 2014

Thanks for the review and thoughts. Will take a look at consuming the real gamepad tonight.

Looks like I should be able to use TouchPanel.GetCapabilities().IsConnected to work out if there is a TouchPanel we can use.

@danzel
Copy link
Contributor Author

danzel commented May 6, 2014

Combining them is going to be a bit clunky.

I basically need the Buttons value from GamePadButtons
https://github.com/mono/MonoGame/blob/develop/MonoGame.Framework/Input/GamePadButtons.cs#L47
But it isn't externally accessible, and creating one from a GamePadButtons is a big bunch of dumb code.

@tomspilman Thoughts on giving Buttons a public getter?

@SimonDarksideJ
Copy link
Contributor

Well submit a PR to the MG repo with the change and then discuss that there.
I thought buttons was accessible in XNA but that may be my addled mind playing tricks on me.

@tomspilman
Copy link
Member

So does anything need to change here or is it good to merge?

Thoughts on giving Buttons a public getter?

I don't see why it is needed. Are the existing individual button state getters in that class not enough?

@SimonDarksideJ
Copy link
Contributor

Needs a few tweaks @tomspilman before it can merge so it's fit for all platforms

@SimonDarksideJ
Copy link
Contributor

Ahh, I see the issue, buttons in the GamePadButtons class is marked as internal
internal Buttons buttons;

Can you not get it from GamePadState @danzel ?

@danzel
Copy link
Contributor Author

danzel commented May 6, 2014

The issue is:
I want to construct a GamePadButtons based on the existing buttons held down by a GamePad, plus my extra buttons.

The only constructor GamePadButtons has takes a Buttons enum.

I get a GamePadButtons object from GamePad.GetState(), but to get the state of the buttons I have to go through each of its public ButtonState properties and generate a Buttons enum from them.

I can do this, but it's a bit clunky. It would be much tidier if we had access to GamePadButtons.buttons, but this would be breaking with XNA.

The clunky way is only about 10 extra lines of code, something like:

buttons |= (gpButtons.A == ButtonState.Pressed ? Buttons.A : 0);
//And so on for each button

I'll do it this way, we keep XNA compatibility in the samples which is nice.

@SimonDarksideJ
Copy link
Contributor

Keeping XNA compatibility sounds like a great idea :D

@danzel
Copy link
Contributor Author

danzel commented May 13, 2014

Have pushed up some more work on this.
We now always run the VirtualGamePad, it won't do anything unless there are touches. It adds the gamepad state to the state it returns.

We only draw the VirtualGamePad if touchState.IsConnected is true, but it looks like it always is. (I tried TouchPanel.GetCapabilities().IsConnected too), might be a monogame bug/not implemented.

Currently touch controls stay visible if other input is being used, will make them disappear when any input is detected.

@SimonDarksideJ
Copy link
Contributor

Sounds good, I'll check it out.

@danzel
Copy link
Contributor Author

danzel commented May 13, 2014

Logged some bugs for the bad IsConnected
MonoGame/MonoGame#2531 MonoGame/MonoGame#2532

@danzel
Copy link
Contributor Author

danzel commented May 13, 2014

And now the virtual controls fade out after any input, so this should be good to go I think.

@danzel
Copy link
Contributor Author

danzel commented May 17, 2014

Don't forget about this :)

@tomspilman
Copy link
Member

Sorry... merged!

tomspilman added a commit that referenced this pull request May 18, 2014
Virtual Gamepad for Platformer2D
@tomspilman tomspilman merged commit 200c49e into MonoGame:develop May 18, 2014
@danzel
Copy link
Contributor Author

danzel commented May 18, 2014

Cool, thanks :)

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.

Platformer2D Touch Input

3 participants