How to port Windows game to Android

Hello,
I’ve made a 2D platformer game for Windows and now I’m thinking about porting it to Android as well. I’ve found some older threads on forum but links no longer work or they’re about Windows Phone. Are there any major differences between how Windows version and Android version of Monogame work?

There’s a few things you need to worry about but it’s not too bad. The biggest thing you’ll need to worry about is how you handle input. I took a very brief look at your code and saw that you’re using Mouse/Keyboard controls. These don’t have Android equivalents. Instead, you’ll need to use the touch screen stuff. If you made a platformer, you’re probably looking at making a virtual controller.

You may want to rethink your controls. How you handle input is very tightly integrated with your Player1 object. Maybe look at pulling this out into an object responsible for determining a set of actions based on some inputs, but abstract this behind an interface so you can implement it for both Windows and Android. Maybe…

public enum InputAction
{
  Up,
  Down,
  Left,
  Right,
  Jump,
  // etc...
}

public interface IInputHandler
{
  InputAction[] GetActions();
}

public class WindowsInputHandler : IInputHandler
{
  private static KeyboardState _oldKeyboardState;

  public override InputAction[] GetActions()
  {
    KeyboardState ks = Keyboard.GetState();
    List<InputActions> actions;
    
    if (ks.IsKeyDown(Keys.Left)) actions.Add(InputAction.Left);
    if (_oldKS.IsKeyDown(Keys.Space) && ks.IsKeyUp(Keys.Space)) actions.Add(InputActions.Jump);
    // etc...

    _oldKS = keyboardState;
    return actions.ToArray();
  }
}

public class AndroidInputHandler : IInputHandler
{
  public override InputAction[] GetActions()
  {
    // However you want to handle the touch screen controls.
  }
}

Then, extend your Game1 class to take the interface as a parameter via its constructor and instantiate the appropriate implementation in either your Program.cs (for Windows) or GameActivity.cs (for Android).

This is just a basic example, but hopefully you see what I’m getting at. You have to handle each differently for the two platforms.

You can take a similar approach if you want to do any file IO for save/load of gamestate. I think those were the two main areas I needed to worry about. There were a few other android specific things like when I wanted to use the back button, but you cross those bridges as you come to them.

Good luck!

1 Like

I would look at Nez core. there is an input class, virtual gamepad there, sticks there,
and this: GitHub - Luiz-Ossinho/Studies.Joystick: Simple virtual joystick implementation on mobile/android, using Monogame

how u simplify your game input via mouse/ buttons vs touch is tricky. also mouse wheel and pinch zoom on windows dx via touch inputs through windows, might get mixed up. Simply putting a virtual game pad or some game buttons on your screen might not be a good port its so much harder to play … also you could try android plus bluetooth or usb game pad.

im using a surface touch to do the ui… then try it on droid hoping it works first try and it soemtimes does, but its still really hard. so i dont’ have to do everything via xamarin or maui which is dog slow still so im hoping for ARM support , vs 2022 on ARM, deploy Android apps on windows, etc. expect to spend weeks or months and lots of changes happening every day around this stuff… it can be done right now but things are changing and you need to keep your eyes open… its takes like minutes to lauch a emulator, its terrible experience and to build and deploy and remote debug is hard as well. Maui doesnt help , its build over Xamarin. USB or wifi debug is sometimes ok but its hard…theres no Edit and Continue, I could go on and have it working but dont expect to deploy it in the app store for a long time tilll things settle. nice part is you should get ios and ipad, on the same code, probably without much extra work…

I recently ported my puzzle game " Scéal - The Story Of Ireland" to Android just to see how difficult it would be (Scéal - The Story Of Ireland by jonathanmcc).

It was actually pretty straight forward - these were the main difficulties:

  • I had to change all mouse input to touch inputs. Right click actions in particular had to be converted to Cancel or Confirm buttons.
  • I had to setup the environment for testing in Android - this involved several downloads
  • I had to deal with screen layout - in particular, landscape v portrait mode. I added code to scale the display up to the size of the android device.

I got it working and running on my phone. When I showed it to someone, they immediately said it was too small. So to make it more viable a screen redsign is necessary.
The non-android version is 1024x768 - the andriod resolutions can be much higher than that.

Oh, this reminds me to mention for the OP… on the topic of screens, heads up for notches. Some devices have a little notch on the screen where a camera goes, but the screen can extend up on either side of it. You sometimes have to take special care to avoid resolution issues with this.

There’s a developer mode setting you can enable to make the simulator device have a notch so you can debug with it.

1 Like