Welcome, Guest. Please login or register. Did you miss your activation email?

Author Topic: Tile map with collision?  (Read 4185 times)

0 Members and 1 Guest are viewing this topic.

Damian

  • Newbie
  • *
  • Posts: 4
    • View Profile
Tile map with collision?
« on: September 02, 2011, 12:38:06 pm »
Hello. I have question that comes with title ;d I know how to make a tilemap but how to detect collision with sprites of Tilemap. ? And i know how to detect normal collision but how to do it with tile map ?:(

Please help

And i dont want ready code. Just explanation.

thePyro_13

  • Full Member
  • ***
  • Posts: 156
    • View Profile
Tile map with collision?
« Reply #1 on: September 02, 2011, 03:18:46 pm »
What I'm doing is creating a tile class which holds a sprite, a rect and a collision bool.

Keep a rect with each of your entity classes as well, and you can easily do a rect intersect to see if you're colliding. And ignore collisions if the tile is non-collide.

If you keep a map of vector positions for your tiles, and let your entities keep track of which tile they're in, then you only need to check the adjacent tiles.

Haikarainen

  • Guest
Tile map with collision?
« Reply #2 on: September 02, 2011, 05:05:18 pm »
What kinda game are you doing? Want it pixelperfect?

I have;
On the player; A rectangle a little bit smaller than the sprite, wich i check for collisions.

On each tile; First check if the playerrectangle intersects with the tiles rect(width and height), if so; Get an intersected rect of them both(sf::Rect::Intersects() returns this i think), and iterate the pixels inside of that, if a nontransparent tilepixel intersects with the playerrectangle; Its a collision! For iterating the pixels, im currently using the old sf::Image::GetPixel, but soon after porting to sfml2, i will generate a collisionmap of bools instead to check for collisions with.

 

anything