specific tile collision not detecting c# xna monogame

  • (2 Pages)
  • +
  • 1
  • 2

19 Replies - 1461 Views - Last Post: 21 December 2016 - 06:32 PM

#16 Skydiver  Icon User is offline

  • Code herder
  • member icon

Reputation: 5828
  • View blog
  • Posts: 19,868
  • Joined: 05-May 12

Re: specific tile collision not detecting c# xna monogame

Posted 20 December 2016 - 10:09 AM

For your player updates, do you ever increment Position.X or Position.Y more than TILE_WIDTH or TILE_HEIGHT? For example do you have a run, jump, or slide action that changes the position more than a single tile's worth of movement?
Was This Post Helpful? 0
  • +
  • -

#17 Skydiver  Icon User is offline

  • Code herder
  • member icon

Reputation: 5828
  • View blog
  • Posts: 19,868
  • Joined: 05-May 12

Re: specific tile collision not detecting c# xna monogame

Posted 20 December 2016 - 07:11 PM

I have never used monodevelop. I heard that it is at parity feature wise to older versions of Visual Studio. Since Visual Studio has always had data breakpoints where you can set the debugger to stop when a variable or memory block changes value to outside a range, you could set such a breakpoint that stops when the position exceeds your tile map bounds. When the debugger stops, it should stop right at the line of code that changed the value to exceed the limits.
Was This Post Helpful? 0
  • +
  • -

#18 AnonymousUser1508  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 18
  • Joined: 29-April 16

Re: specific tile collision not detecting c# xna monogame

Posted 21 December 2016 - 06:27 AM

Hi Again,

I do not have any slide, dash or jump movements. I reduced the speed slightly and it seemed to have fixed the issue, ran it multiple times and not one error has popped up. Thank you both very much for your help by the way, it's been much appreciated.
Was This Post Helpful? 0
  • +
  • -

#19 Skydiver  Icon User is offline

  • Code herder
  • member icon

Reputation: 5828
  • View blog
  • Posts: 19,868
  • Joined: 05-May 12

Re: specific tile collision not detecting c# xna monogame

Posted 21 December 2016 - 07:12 AM

The proper fix would to do a bounds check at the end of your player movement update routine to make sure that they are still within the current view (unless you are actually using the out of bounds state to trigger a scroll).
Was This Post Helpful? 0
  • +
  • -

#20 SixOfEleven  Icon User is offline

  • Planeswalker
  • member icon

Reputation: 1055
  • View blog
  • Posts: 6,643
  • Joined: 18-October 08

Re: specific tile collision not detecting c# xna monogame

Posted 21 December 2016 - 06:32 PM

Array indexes are 0 based in C#. You have 7 rows and 7 columns. So, your array is [0-6,0-6]. If the value is 7 that is clearly out of the bounds of 0 to 6.

The way I would tackle collision detected is first, grab the player's position. Second, grab the direction that they player wants to move. If the player does not want to move exit the method in some manner appropriate to its signature. Next, add the player's position and the direction and add them together. Test if that movement would place they off the map. If it would just exit the method the same as above. Finally, check if the player is allowed to move into that map location. If they can't exit the method. Since all other checks to see if the player is not allowed to move update the player's position with the desired direction.
Was This Post Helpful? 0
  • +
  • -

  • (2 Pages)
  • +
  • 1
  • 2