Hello Guest

Author Topic: Best way to find out what tile is "next to" an object?  (Read 4202 times)

scottstephan

  • 2D Toolkit
  • Newbie
  • *
  • Posts: 6
    • View Profile
Best way to find out what tile is "next to" an object?
« on: May 30, 2013, 11:10:30 pm »
I'm working on a turn-based game in which players can't pass certain environmental objects- rocks, water etc. Because the game is turn based, they get a set of availabe movement directions at the start of their turn. The way I did this back in ye olden Actionscript days was to have an array of tile and then check around the player to see if any of the directions were impassable.

2DToolkit doesn't have an array of tiles (I don't think!), so what're my best options and practices for checking for impassable directions around the player? My current idea is to have 4 small, sub objects around the player sprite, each one tile north, south east and west. Check for collisions and report back.

Is there a smarter way with the tools available in 2DTK?

unikronsoftware

  • Administrator
  • Hero Member
  • *****
  • Posts: 9709
    • View Profile
Re: Best way to find out what tile is "next to" an object?
« Reply #1 on: May 30, 2013, 11:12:49 pm »
No, but surely if its tile based, you could always have an array representing all the tiles and tile types. The render gfx is purely that, render gfx. Personally, I would not try to mix that with game logic like this. It would be a lot simpler to split up game data, and update the render data appropriately.

srivello

  • 2D Toolkit
  • Newbie
  • *
  • Posts: 6
    • View Profile
Re: Best way to find out what tile is "next to" an object?
« Reply #2 on: May 31, 2013, 12:22:39 pm »
2DToolkit does indeed support tile-based games. Typically a game is either tile-based or not. It is not a mixture. I assume your game is not tilebased.

TILEBASED

If tilebased you can define the map via tk2dTileMap Class and do the lookup and type-check for the tile in the space the player is about to walk into.

NOT TILEBASED

Unity is VERY fast in its computation. A developer can do more expensive techniques than he/she could do in other, older, slower platforms. So your idea to put 'trigger collider' objects (invisible with just a collider) to do testing is a great idea. Often there is just 3 at the players feet (center x, left x, and right x) and you test just the one in the direction you are going (left/right/down). If you need more tests you can do more.