I had just finished implementing a text file parser so that I could easily design game tiles in a text file, turn them into a Texture2D, then use them as sprites in my game. I don’t know if this is related to my issue. When I went to build the project, the graphics were off. A sprite that’s supposed to be square (8x8 pixels) is squeezed, the pixels are sometimes not square, and there’s this weird margin on the side of the viewport where the sprite doesn’t even get drawn.
This is something that happens a lot when there’s some kind of scaling going on. When you’re rendering a position at a float value instead of an integer one, or using a Matrix transform in your SpriteBatch.Begin call.
From the sample code you’ve posted though, I don’t see any scaling going on. You’re adding a full scale factor of 3, but you’re always multiplying this integer by other integers and I don’t see any division happening.
So I’m not sure why this is happening. Based on your code the agent renders in a filled white rectangle, which doesn’t appear on the screen, so unless there’s more code to it, those screens are fully rendered by the “board” code in the first code block you posted?
The only thing I can think of is for you to check how board[y, x] is generated. It looks like you’re storing data to that as a full screen array, then rendering each element of the array as a pixel to your screen. Is the data in that array as you expect it to be?
Past that, I can’t think of anything else… you may have to post a more complete solution via github or something.
player.Sprite is actually the blue square you see, not a filled white rectangle. I checked board several times, but I couldn’t find any issue with it… Plus, that doesn’t explain why the player sprite gets cut off near the right edge of the screen.
I’ve uploaded my project file to Github… if you’re willing to take a look.
I think I figured it out. In the initialization function for my Agents class, I define a new GraphicsDevice when I could be using _graphics.GraphicsDevice (_graphics being my GraphicsDeviceManager) from the Game1 class. I’m not exactly sure what the difference between the two devices are, but fixing it so that the Agents classe referenced the same variable fixed my issues!
Oh right, you’re not rendering that with a pixel, it’s an actual sprite
Hmm weird. I know you definitely don’t need to use that, you can just share the one from your main game project over. Having said that, looking at the code you posted on github, you don’t actually reference that device… just create it and hang onto it. The SpriteBatch you render with for Agent is passed in to the Draw method, and that SpriteBatch was created by your main game class with its own GraphicsDevice.
This is definitely a strange one! Perhaps someone more well versed in what GraphicsDevice does might be better able to shed some light as to why just creating another one can skew your screen rendering.