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

Author Topic: Quick Question about objects and tiles  (Read 1436 times)

0 Members and 1 Guest are viewing this topic.

smilesprower

  • Newbie
  • *
  • Posts: 25
    • View Profile
    • Email
Quick Question about objects and tiles
« on: October 04, 2016, 08:26:52 pm »
Is it better to have a tile ref/point to an object or use and ID and loop through the vector of objects and decide which object were talking about ?

Also what if we have multiple objects on the same tile ?

eXpl0it3r

  • SFML Team
  • Hero Member
  • *****
  • Posts: 11034
    • View Profile
    • development blog
    • Email
AW: Quick Question about objects and tiles
« Reply #1 on: October 04, 2016, 09:31:57 pm »
These seem like rather vague questions. What objects are you talking about here? And do you mean tile as in the position on the "grid" or as visual representation?

Maybe you can tell us a bit more about your current setup and make the questions slightly more precise? :)
Official FAQ: https://www.sfml-dev.org/faq.php
Official Discord Server: https://discord.gg/nr4X7Fh
——————————————————————
Dev Blog: https://duerrenberger.dev/blog/

smilesprower

  • Newbie
  • *
  • Posts: 25
    • View Profile
    • Email
Re: Quick Question about objects and tiles
« Reply #2 on: October 04, 2016, 11:50:36 pm »
Hope this is better explanation.

For example, the player walks on tile which also happens to be the same position as a item.
Is it better for the tile to have a reference to the exact item the player collides with,
or loop through a whole list of items to see which one the player collided with based on ID or Pos ?

Yohdu

  • Newbie
  • *
  • Posts: 26
    • View Profile
    • Email
Re: Quick Question about objects and tiles
« Reply #3 on: October 05, 2016, 08:51:51 am »
In my opinion, it may be useful to have both.

When you set the position of your game objects on the map, if you manage to compute the tile(s) that are containing it (which is quite straight-forward), then it is a good solution to have your tiles owning reference to these items so that you can directly check the tile(s) that your character is on.

However, you could also at some point in your game have to iterate through all the objects on your map for whatever reason. In that case, it would be better to have a container having a reference to all of these objects. This container could be a std::vector, but it also could be a more advanced data model like a binary/quad tree to spacially divide your map and accessing faster to specific game objects for example.

So yeah, both solutions are good, it really depends on your game and what you want to achieve with it.
« Last Edit: October 05, 2016, 08:54:24 am by Yohdu »