Any alternative on Virtual joystick?

I just found out that virtual gamepad in no longer on monogame. Is there any alternative for this gamepad joystick? Like this

There’s not much example for that.


Here’s the twin stick code I wrote for Square Off. You can test it out in Windows Phone/Android/iOS stores.

It supports a mode I call “free follow” where you can start the touch anywhere in the left/right side of the screen and the joystick will follow your finger if it gets too far away. That makes for the most playable virtual twin stick I find. This code doesn’t draw the joystick for you, but that should be easy using SpriteBatch and doing something like this:

if (TouchTwinStick.UsingLeftStick)
    spriteBatch.Draw(... ... ,TouchTwinStick.leftStickPos, ...);

[EDIT] Forgot to mention some other features. Barring gesture recognition, it can probably replace all usages of TouchPanel. In fact it probably should because you don’t want to be calling TouchPanel.GetTouches more than once a frame!:

  • left/right stick direction fields (not normalised)
  • left/right stick magnitude fields
  • dead zone handling
  • valid regions to initiate left/right stick movements
  • justTouched and justTapped fields for simple touch and button press handling
  • TouchCount and FirstTouch for easy checking of single finger input.
  • GetGamepadState() (doesn’t do buttons of course)
1 Like

OMG thanks. Ill sure try this

EDIT : I downloaded the game. It looks great btw did you use spine2D for the animation? Like for example the arms rotate 360 degrees?

Thanks! :smile:
If you mean Square Off, no. It used an animation tool I wrote in 2009 that is kind of like spine, but heaps less awesome. The characters are rigged in the tool, and animations can contain frame swaps, translations and rotations, but the arm rotation is just procedural - they match the direction you are aiming.

Interesting point - the game in that github repo is Queen of Heart (codename spineless) and we used that game jam as a way to develop our animation tools. The old tool turned out to be too hard to get the artist to use, so instead I built a javascript flash exporter and animation library based on a blog post by Catalin Zima. We’ve used this for Square Heroes.

Thank you for this code. I wanted to use it, but found out that it is static and i can not control how it behaves on different screen sizes. So i refactored heavily, made non-static, added basic drawing, etc. Not sure if someone is interested, but i am going to upload it to GitHub in near future.

Great! Happy it inspired you to improve upon it :). Static worked for me as TouchPanel itself is static and I considered it a helper/replacement for that.

made it!

1 Like

Hello, If you have these improvements to the virtual game pad, i’m curious to see them on github…

Oh never mind it see it now, Thanks

Hey, its been long but i have my own implementation, should be quite easy to understand.