Created
February 11, 2016 21:15
-
-
Save Cleroth/5dbf5c4c03ddee9e59ef to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const auto & font = app->_fonts[0]; | |
auto prev_view = tgt->getView(); | |
// GetPos() gets the unit's world position (shape world position for you) | |
auto world_pos = GetPos(); | |
world_pos.y -= 11 + font.size; | |
auto screen_pos = tgt->mapCoordsToPixel(world_pos); | |
auto view = tgt->getDefaultView(); | |
view.setSize({(float)app->GetResolution().x, (float)app->GetResolution().y}); | |
tgt->setView(view); | |
auto pos = tgt->mapPixelToCoords(screen_pos); | |
// Draw name | |
sf::Text text(GetName(), font.font, font.size); | |
auto bounds = text.getGlobalBounds(); | |
text.setOrigin({bounds.width / 2, bounds.height}); | |
text.setColor({255, 255, 255}); | |
text.setPosition(pos); | |
tgt->draw(text); | |
tgt->setView(prev_view); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment