SFML community forums

Help => General => Topic started by: smilesprower on October 04, 2016, 08:26:52 pm

Title: Quick Question about objects and tiles
Post by: smilesprower 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 ?
Title: AW: Quick Question about objects and tiles
Post by: eXpl0it3r 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? :)
Title: Re: Quick Question about objects and tiles
Post by: smilesprower 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 ?
Title: Re: Quick Question about objects and tiles
Post by: Yohdu 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.