【发布时间】:2011-09-26 21:41:27
【问题描述】:
过去几周我一直在尝试学习 f#,但在某些方面遇到了一些麻烦。我正在尝试将它与 XNA 一起使用,并且正在编写一个非常简单的游戏。
我有一个简单的播放器类,它实现了 DrawableGameComponent,然后覆盖了它的方法 Draw、Update 和 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)
等等……
然后主 Game 类创建一个新的玩家对象等。
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
编译器报错说“找不到方法或对象构造函数LoadContent”
我觉得这很奇怪,因为 Draw 和 Update 都可以正常工作,并且可以被智能感知找到,但 LoadContent 却没有!
这可能只是我犯的一个非常愚蠢的错误,但如果有人发现问题,我将非常感激!
谢谢
【问题讨论】:
标签: visual-studio-2010 f# xna