In my last post I showed how to get a Monogame Game class running on MacOS. This time it’s Android’s turn.
I’m going to assume you already have Xamarin Studio, the F# Android templates and Monogame installed.
Getting started
Create a new “Android Application” from under the F# Language tree node.
Add references to MonoGame.Framework.dll and Lindgren.Network.dll for Android. You’ll also need a reference to OpenTK (not 1.0).
Using the same Game definition from the MacOS tutorial –
type Game() as game = inherit Microsoft.Xna.Framework.Game() let manager = new Microsoft.Xna.Framework.GraphicsDeviceManager(game) override __.Draw _ = game.GraphicsDevice.Clear Microsoft.Xna.Framework.Color.CornflowerBlue
In MainActivity.fs change the MainActivity to inherit from
Microsoft.Xna.Framework.AndroidGameActivity
And in the OnCreate member replace the content with
override this.OnCreate (bundle) = base.OnCreate (bundle) Game.Activity <- this let game = new Game() this.SetContentView(game.Window) game.Run()
You should now see a lovely blue screen when running on an Android Device. I highly recommend owning an Android device for development as the emulators are rather slow….
Quick note:
On other platforms you usually put Content in the Content folder. On Android you’ll put content in the Assets/Content. For the content add it to the project and set it’s Build Action to AndroidAsset. I’ll be covering building assets for different platforms using the content pipeline in a future post, but in Monogame you can also load some files (such as png) without pre-processing through the content pipeline.
Pingback: F# Weekly #31 2013 | Sergey Tihon's Blog
Pingback: Xamarin Link Roundup – 6 Aug 2013 | Well Technically…
Pingback: F# and Monogame Part 4 – Content Pipeline | Neil Danson's Blog
Pingback: F# on Android