I am experimenting a bit with F# and I am wanted to see if I could do some simple stuff with Monogame in F#. I figured the translation from C# to f# would be straightforward but it has not been so far. The code I have so far is just a simple empty project which should run. Or at least it would in C#. However running this in F# yields a
Unhandled exception. System.InvalidOperationException: No Graphics Device Service
The code I have is this, which really does not do anything crazy. I was forced to use a mutable val for the spritebatch as you must instantiate it in LoadContent for whatever reason. Anyone have any pointers to what I am doing wrong? I would be most grateful.
type GameState =
inherit Game
new() = { inherit Game(); Sb = null; }
member this.Gfx : GraphicsDeviceManager = new GraphicsDeviceManager(this)
val mutable Sb : SpriteBatch
override this.Initialize() =
this.Content.RootDirectory <- "Content"
this.IsMouseVisible <- false
base.Initialize ()
override this.LoadContent () =
this.Sb <- new SpriteBatch(this.Gfx.GraphicsDevice)
base.LoadContent ()
override this.UnloadContent () =
base.UnloadContent ()
override this.Update (gameTime : GameTime) =
base.Update (gameTime)
override this.Draw (gameTime : GameTime) =
this.Gfx.GraphicsDevice.Clear (Color.CornflowerBlue)
this.Sb.Begin()
//draw here
this.Sb.End()
base.Draw (gameTime)
[<EntryPoint>]
let main argv =
let gs = new GameState()
gs.Run()
0 // return an integer exit code