I am trying to draw pixel by pixel using XNA, but I have problems with resources. I thought the best way is to have 1 texture that updates every frame, but I am having problems updating it. Here is what I got so far as a test:
Texture2D canvas; Rectangle tracedSize; UInt32[] pixels; protected override void Initialize() { tracedSize = GraphicsDevice.PresentationParameters.Bounds; canvas = new Texture2D(GraphicsDevice, tracedSize.Width, tracedSize.Height, false, SurfaceFormat.Color); pixels = new UInt32[tracedSize.Width * tracedSize.Height]; base.Initialize(); } protected override void Draw(GameTime gameTime) { GraphicsDevice.Clear(Color.CornflowerBlue); pixels[100] = 0xFF00FF00; canvas.SetData<UInt32>(pixels, 0, tracedSize.Width * tracedSize.Height); spriteBatch.Begin(); spriteBatch.Draw(canvas, new Rectangle(0, 0, tracedSize.Width, tracedSize.Height), Color.White); spriteBatch.End(); base.Draw(gameTime); }
When Draw () is called a second time, I get the following error:
"The operation was interrupted. You cannot change the resource that was installed on the device, or after it was used in the bracket for the tile."
If I try to create a new Texture2D in Draw (), I quickly get an error from memory. This is for Windows Phone. It looks like I'm trying to do it wrong, what other options do I need to make it work?
c # xna 2d
Curyous
source share