Hello,
I'm assuming there must be some people here who have read this awesome book. I'm towards the end now and I'm trying to do something very simple and it is not coming out right at all. It could be I am not understanding how they are positioning the tiles.
I'm trying to add some simple path-finding. The way I usually do it is grabbing the tile underneath position and adding it to a vector. Thus, creating the path to the destination. But I am having trouble just getting the tile position in general!
I have a simple function that displays values of various things to sf::Text, one being the position of the sprite the tile is on and it is never correct. It seems to only change when a new tile is underneath the player. For example, all the grass tiles say (2016x2016), but when I move to a tile that might be the edge of grass it changes. Yet I am retrieving the tile sprite from TileInfo and using getPosition. I tried to see what happened if I just changed the tiles color instead and no luck.
auto posComp = m_stateMgr->getContext()->m_entityManager->getComponent<C_Position>(m_player, Component::Position);
auto gameMap = m_stateMgr->getContext()->m_gameMap;
auto currTile = gameMap->getTileMap()->getTile(floor(posComp->getPosition().x/32), floor(posComp->getPosition().y)/32, 0);
std::cout << currTile->m_properties->m_sprite.getPosition().x << ", " << currTile->m_properties->m_sprite.getPosition().y << "\n";
I would really like to continue to use the engine provided in the book, so any help would be appreciated. Thanks!
PS: For those who would like to help I can provide anything you would need to know!