XNA 4.0 - 窗口最小化时会发生什么?
我正在学习 F#,并决定尝试使用 F#(纯粹的热情)为 Windows 制作简单的 XNA 游戏,并得到一个显示一些图像的窗口。
代码如下:
(*Methods*)
member self.DrawSprites() =
_spriteBatch.Begin()
for i = 0 to _list.Length-1 do
let spentity = _list.List.ElementAt(i)
_spriteBatch.Draw(spentity.ImageTexture,new Rectangle(100,100,(int)spentity.Width,(int)spentity.Height),Color.White)
_spriteBatch.End()
(*Overriding*)
override self.Initialize() =
ChangeGraphicsProfile()
_graphicsDevice <- _graphics.GraphicsDevice
_list.AddSprite(0,"NagatoYuki",992.0,990.0)
base.Initialize()
override self.LoadContent() =
_spriteBatch <- new SpriteBatch(_graphicsDevice)
base.LoadContent()
override self.Draw(gameTime : GameTime) =
base.Draw(gameTime)
_graphics.GraphicsDevice.Clear(Color.CornflowerBlue)
self.DrawSprites()
AddSprite 方法:
member self.AddSprite(ID : int,imageTexture : string , width : float, height : float) =
let texture = content.Load<Texture2D>(imageTexture)
list <- list @ [new SpriteEntity(ID,list.Length, texture,Vector2.Zero,width,height)]
_list 对象有一个 ContentManager,这是构造函数:
type SpriteList(_content : ContentManager byref) =
let mutable content = _content
let mutable list = []
但我无法最小化窗口,因为当它重新获得焦点时,我收到此错误:
ObjectDisposeException
无法访问已处置的对象。
对象名称:“GraphicsDevice”。
怎么了?
I'm learning F#, and decided to try making simple XNA games for windows using F# (pure enthusiasm) , and got a window with some images showing up.
Here's the code:
(*Methods*)
member self.DrawSprites() =
_spriteBatch.Begin()
for i = 0 to _list.Length-1 do
let spentity = _list.List.ElementAt(i)
_spriteBatch.Draw(spentity.ImageTexture,new Rectangle(100,100,(int)spentity.Width,(int)spentity.Height),Color.White)
_spriteBatch.End()
(*Overriding*)
override self.Initialize() =
ChangeGraphicsProfile()
_graphicsDevice <- _graphics.GraphicsDevice
_list.AddSprite(0,"NagatoYuki",992.0,990.0)
base.Initialize()
override self.LoadContent() =
_spriteBatch <- new SpriteBatch(_graphicsDevice)
base.LoadContent()
override self.Draw(gameTime : GameTime) =
base.Draw(gameTime)
_graphics.GraphicsDevice.Clear(Color.CornflowerBlue)
self.DrawSprites()
And the AddSprite Method:
member self.AddSprite(ID : int,imageTexture : string , width : float, height : float) =
let texture = content.Load<Texture2D>(imageTexture)
list <- list @ [new SpriteEntity(ID,list.Length, texture,Vector2.Zero,width,height)]
The _list object has a ContentManager, here's the constructor:
type SpriteList(_content : ContentManager byref) =
let mutable content = _content
let mutable list = []
But I can't minimize the window, since when it regains its focus, i get this error:
ObjectDisposedException
Cannot access a disposed object.
Object name: 'GraphicsDevice'.
What is happening?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
好吧,经过一段时间的努力,我终于开始工作了。但这似乎并不“正确”
(这样想,使用 XNA 和 F# 似乎也不正确,但它很有趣。)
每当我的游戏需要 LoadContent 时,我都会调整 GraphicsDevice,并在 DrawSprites() 方法中检查纹理是否已释放,如果是的话,重新加载。
但这件事让我烦恼。我不知道每次窗口最小化时都必须再次加载所有内容。
(代码看起来像 Initialize() 加载内容,然后 LoadContent() 初始化,但是哦,好吧)
Well after struggling for some time I got it to work. But it doesn't seem "right"
(thinking that way, using XNA and F# doesn't seem right either, but it's fun.)
I adjust the graphicsDevice whenever my game needs to LoadContent, and in the DrawSprites() method I check if the texture is disposed, if it is, load it up again.
But this thing bugs me. I didn't know I had to Load all Content again everytime the window is minimized.
(And the code makes it look like Initialize() loads Content, and LoadContent() initializes, but oh well)
您所观察到的是正常行为,顺便说一下,它不是 F# 所特有的。请参阅 http://msdn.microsoft.com/ zh-cn/library/microsoft.xna.framework.game.loadcontent.aspx
您是否正在 Game.LoadContent 中加载所有内容?如果这样做,您不应该收到这些错误。
What you are observing is normal behaviour, it's by the way not specific to F#. See http://msdn.microsoft.com/en-us/library/microsoft.xna.framework.game.loadcontent.aspx
Are you loading all of your content in Game.LoadContent? If you do, you should not be getting these errors.