2 Replies - 1366 Views - Last Post: 18 September 2013 - 05:27 PM

#1 Rhino1111   User is offline

  • D.I.C Regular
  • member icon

Reputation: 107
  • View blog
  • Posts: 259
  • Joined: 28-August 13

Weird Drawing Behaviour

Posted 18 September 2013 - 04:48 PM

Here's my code:

spriteBatch.Begin();
           for (int y = 0; y < 15; y++)
           {
               for (int x = 0; x < 16; x++)
               {
                   for (int z = 0; z < 4; z++)
                   {
                       if (map.map[x + EditingVariables.OffsetX, y + EditingVariables.OffsetY, z] != null)
                       {
                           Rectangle dest = new Rectangle(x * 32, y * 32, 32, 32);
                           Rectangle source = TileHelper.GetPosition(map.map[x + EditingVariables.OffsetX, y +         EditingVariables.OffsetY, z].tileID);
                           
                           spriteBatch.Draw(tileSets[(TileHelper.GetTileSet(map.map[x + EditingVariables.OffsetX, y + EditingVariables.OffsetY, z].tileID)) + 1], dest, source, Color.White); 

                       }
                   }
               }
           }
           spriteBatch.End();


Now to explain the problem. Basically my render area can display 16 tiles wide, and 15 tiles high. this is why I loop through the x and y those number of times. I set up numerous breakpoints and all the values are correct (destination rectangle goes from 0,0,32,32 to 32,0,32,32, etc, etc). And the source rectangle returned from the "TileHelper.GetPosition" method returns the source rectangle fine as well.

For some reason, when it draws...the dimensions are completely messed up....


The Y seems to be almost correct, but the X seems like its being compressed.

Posted Image

As you can see, despite the source and destination rectangle having the correct values, its drawing all messed up :S

I've debugged for quite a while and nothing in the draw routine is returning weird values, any idea's?

Is This A Good Question/Topic? 1
  • +

Replies To: Weird Drawing Behaviour

#2 Rhino1111   User is offline

  • D.I.C Regular
  • member icon

Reputation: 107
  • View blog
  • Posts: 259
  • Joined: 28-August 13

Re: Weird Drawing Behaviour

Posted 18 September 2013 - 04:54 PM

I guess it's probably also worth mentioning that I'm rendering onto a windows forms picturebox from the xna game.
Was This Post Helpful? 0
  • +
  • -

#3 Rhino1111   User is offline

  • D.I.C Regular
  • member icon

Reputation: 107
  • View blog
  • Posts: 259
  • Joined: 28-August 13

Re: Weird Drawing Behaviour

Posted 18 September 2013 - 05:27 PM

Ok I'm really sorry for the triple post, but I dont see any edit options anywhere!
I solved the problem.

It ended up being something really stupid. I was messing around with the preferred backbufferwidth/height (game size) before I turned this into a tile editor project. The dimensions were off because my xna game size didn't match the size of my picturebox. When I fixed those 2 lines of code everything drew perfectly!
Was This Post Helpful? 1
  • +
  • -

Page 1 of 1