Jump to content

  • Log In with Google      Sign In   
  • Create Account

Interested in a FREE copy of HTML5 game maker Construct 2?

We'll be giving away three Personal Edition licences in next Tuesday's GDNet Direct email newsletter!

Sign up from the right-hand sidebar on our homepage and read Tuesday's newsletter for details!


We're also offering banner ads on our site from just $5! 1. Details HERE. 2. GDNet+ Subscriptions HERE. 3. Ad upload HERE.


2D tiles and XNA


Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.

  • You cannot reply to this topic
3 replies to this topic

#1 greencrayon   Members   -  Reputation: 138

Like
0Likes
Like

Posted 23 July 2007 - 10:57 PM

Hi folks. I am using C# and XNA. I have seen that a lot of 2d games use some sort of tile-based collision in platform/maze/rpg type games, and have been trying to work out how to do this but all of the examples/tutorials I have managed to find seem to go a bit deeper than I am able to understand. They often include scrolling and movement physics and all kinds of other complicated stuff and I can’t weed out the bits I need. What I want is just the collision detection and response part. I can use a 2d vector of ints representing tiles to draw my game screen, and I can put a moving character sprite onto the screen. But I cannot make it so that the character can only move in the areas I want it to. I read something about making tiles walkable/non-walkable. How would I do this? And more importantly, how do I know my character’s position in regards to the type of tile it is standing on? I would be great if anyone can give me a very simple example or point me in the direction of a tutorial that concentrates solely on the collision detection aspect of a tile-based game.

Sponsor:

#2 Butterman   Members   -  Reputation: 132

Like
0Likes
Like

Posted 24 July 2007 - 12:06 AM

If you have a second array of integers to represent the tiles, you can have them on either '1' (which will trigger a collision) or '0' (which means you can walk past the tile). So [1][1] = 1; Will make that tile collidable. Then you take the players co-ordinates and pump them into this formula,



//Find the tile that the player is on, on the X axis
PlayerTileX = PlayerX / TileSize;
//Find the tile that the player is on, on the Y axis
PlayerTileY = PlayerY / TileSize;

//If the tile is collidable, stop player movement
if(array[PlayerTileY][PlayerTileX] == 1)
{

PlayerMove = false;

}






Simple. Eh?

#3 greencrayon   Members   -  Reputation: 138

Like
0Likes
Like

Posted 24 July 2007 - 12:09 AM

Yes very simple, doh. Probably why I could not find any tutorials on it. For the same reason you dont see many online tutorials on how to inhale. Thanks for the help, that is exactly what I wanted.

#4 Butterman   Members   -  Reputation: 132

Like
0Likes
Like

Posted 24 July 2007 - 12:13 AM

Well actually, if you go here:

http://www.xnaresources.com/pages.asp?pageid=8

In one of the tutorials you will find similar code to what ive just shown you,




Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.



PARTNERS