I have been trying to learn f# over the past few weeks and am having a little trouble with certain aspects. I am trying to use it with XNA and am writing a very simple game.
I have a simple player class that implements DrawableGameComponent and then overrides its methods Draw, Update and LoadContent.
type Player (game:Game) =
inherit DrawableGameComponent(game)
let game = game
let mutable position = new Vector2( float32(0), float32(0) )
let mutable direction = 1
let mutable speed = -0.1
let mutable sprite:Texture2D = null
override this.LoadContent() =
sprite <- game.Content.Load<Texture2D>("Sprite")
override this.Update gt=
if direction = -1 && this.Coliding then
this.Bounce
this.Jumping
base.Update(gt)
override this.Draw gt=
let spriteBatch = new SpriteBatch(game.GraphicsDevice)
spriteBatch.Begin()
spriteBatch.Draw(sprite, position, Color.White)
spriteBatch.End()
base.Draw(gt)
and so on....
The main Game class then makes a new player object etc.
module Game=
type XnaGame() as this =
inherit Game()
do this.Content.RootDirectory <- "XnaGameContent"
let graphicsDeviceManager = new GraphicsDeviceManager(this)
let mutable player:Player = new Player(this)
let mutable spriteBatch : SpriteBatch = null
let mutable x = 0.f
let mutable y = 0.f
let mutable dx = 4.f
let mutable dy = 4.f
override game.Initialize() =
graphicsDeviceManager.GraphicsProfile <- GraphicsProfile.HiDef
graphicsDeviceManager.PreferredBackBufferWidth <- 640
graphicsDeviceManager.PreferredBackBufferHeight <- 480
graphicsDeviceManager.ApplyChanges()
spriteBatch <- new SpriteBatch(game.GraphicsDevice)
base.Initialize()
override game.LoadContent() =
player.LoadContent () //PROBLEM IS HERE!!!
this.Components.Add(player)
override game.Update gameTime =
player.Update gameTime
override game.Draw gameTime =
game.GraphicsDevice.Clear(Color.CornflowerBlue)
player.Draw gameTime
The compiler reports an error saying "Method or object constructor LoadContent not found"
I find this odd as both Draw and Update work ok and are found by intellisense but not LoadContent!
It is probably just a very silly error I have made but if anyone spots the problem I would be much obliged!
Thanks