xna

Garbage collector behaviour

亡梦爱人 提交于 2019-12-11 11:16:57
问题 I use C# (with XNA 4 and MonoGame). I load assets (textures, audio) using the Load() method of the Content Manager. When these assets are no longer needed, how can I properly Unload() them from memory? I assume that once all references to the loaded assets are overwritten (or set to null) the assets are automatically removed by the Garbage collector. Is this correct or are the assets still locked due to the fact that they were loaded through the ContentManager? Is it necessary to call

Why does changing the graphics setting after doing so in the `LoadContent` method fail?

生来就可爱ヽ(ⅴ<●) 提交于 2019-12-11 10:45:19
问题 If I set the graphics settings in the Initialize method and then in the Update method, like so: protected override void Initialize() { graphics.ApplyChanges(); base.Initialize(); } protected override void Update(GameTime gameTime) { graphics.ApplyChanges(); base.Update(gameTime); } Everything is fine. However, when I move the code to my LoadContent method like so: protected override void LoadContent() { spriteBatch = new SpriteBatch(GraphicsDevice); graphics.ApplyChanges(); } protected

Parsing this XML file to a Dictionary?

拈花ヽ惹草 提交于 2019-12-11 10:16:48
问题 I'm very new to XML serialization, up until now I've been using XDocument and iterating through an XML file to load stuff up. I know there's a way to serialize XML files, recently I came across the following bit of XML: <?xml version="1.0" encoding="utf-8" ?> <XnaContent> <Asset Type="System.Collections.Generic.Dictionary[System.String, Microsoft.Xna.Framework.Rectangle]"> <Item><Key>frame0</Key><Value>0 0 128 128</Value></Item> <Item><Key>frame1</Key><Value>128 0 128 128</Value></Item> <

Per Pixel Collision - Could do with some general tips

痴心易碎 提交于 2019-12-11 10:09:23
问题 I understand the theory behind Per Pixel Collision in Xna, you get the texture data from two textures, and then compare them, checking the alpha values of, for example, your character texture. What I'm wanting to do is use Per Pixel Collision to check if the Player Sprite has touched the map by checking for collisions with a certain colour (Black). I've tried implementing this before, but the characters always falls through the map with no programming errors thrown. Please point me towards

Is there an inexpensive way to transfer colour data from a RenderTarget2D on a per frame basis?

↘锁芯ラ 提交于 2019-12-11 09:52:32
问题 Until recently, our game checked collisions by getting the colour data from a section of the background texture of the scene. This worked very well, but as the design changed, we needed to check against multiple textures and it was decided to render these all to a single RenderTarget2D and check collisions on that. public bool TouchingBlackPixel(GameObject p) { /* Calculate rectangle under the player... SourceX,SourceY: Position of top left corner of rectangle SizeX,SizeY: Aproximated (cast

XNA Apply effect on BasicEffect

眉间皱痕 提交于 2019-12-11 09:29:00
问题 I'm making a game in XNA 4.0 and I really don't understand the effect and basiceffect stuff. I currently have this: foreach (ModelMesh mesh in model.Meshes) { foreach (BasicEffect effect in mesh.Effects) { if (mesh.Name != collisionShapeName) { effect.TextureEnabled = true; effect.Texture = _textures[name]; effect.SpecularColor = new Vector3(_specularColor); effect.SpecularPower = 32; } } } And I have found a tutorial for rendering shadow and I need to apply this code on mine: foreach

Suggested approach for Photoshop-like blending modes in XNA

馋奶兔 提交于 2019-12-11 09:27:57
问题 I'm working on a 2D project in C# using XNA where I need to render a number of grayscale sprites onto a Texture2D - I'm switching render states and using a sprite batch and getting results mainly thanks to other stackoverflow posts. What I haven't been able to find is how to blend using something other than Alpha or Multiply. The result I'm looking for would be equivalent to the Lighten blending mode in Photoshop - between the contents of the texture and the sprite I'm drawing, I only really

XNA VideoPlayer object causes 'CrossThreadMessagingException'

别来无恙 提交于 2019-12-11 07:44:05
问题 (Relating to an earlier question of mine: Playing a Video (MSDN Tutorial)) I have the following problem: When I'm trying to read the state of a XNA VideoPlayer object I get an CrossThreadMessagingException . Meaning, I'm trying to read from a different thread. This seems to be not allowed (I have no idea how threads work in C# internally :-) Any ideas on how to fix this? (Is there a way to tell the VideoPlayer object to write in a buffer or something?) Code: protected override void Update

True stereoscopic quad buffering in XNA

孤街醉人 提交于 2019-12-11 07:34:27
问题 We are trying to make 3D stereoscopy work within XNA for Windows PC Games using NVidia 3D Vision, we really have no idea how this would be achieved and are just now skimming through the XNA documentation, while we found some examples for anaglyph 3D, we were wondering if there was any way to make it work with the Active glasses that NVidia bundles with its 3D Vision package. We would also love to hear any alternatives as to how we could make this work on Xbox360, without the glasses of course

Implementing per pixel collision on rotated sprites

有些话、适合烂在心里 提交于 2019-12-11 07:27:00
问题 I am building a 2D game in XNA using C#, and I am using sprites that will track the player's position and rotate accordingly in the spritebatch.Draw() method. I am now trying to implement per-pixel collision detection, and I believe that the rotation of the sprites is throwing it off. The collision checks are as follows. private bool collision(Rectangle object1, Color[,] dataA, Rectangle object2, Color[,] dataB) { if (object1.Bottom < object2.Top) return perPixel(object1, dataA, object2,