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

Author Topic: Need a tiny little bit of help [Solved]  (Read 4236 times)

0 Members and 1 Guest are viewing this topic.

2ant

  • Newbie
  • *
  • Posts: 17
    • View Profile
Need a tiny little bit of help [Solved]
« on: February 20, 2015, 10:08:44 pm »
Hi, currently i display the position of a sprite in the titlebar for monitoring purposewith this code:

sf::Vector2f positioncurseur = curseur.getPosition();

std::string cursx = std::to_string ( positioncurseur.x );
std::string cursy = std::to_string ( positioncurseur.y );

title += cursx;
title += " ";
title += cursy;

It works well and give me this :



It annoy me since it is for a t-rpg with a grid so no decimals are needed.

Is it possible to remove the zeroes and the dot without too many lines of code ?
« Last Edit: February 20, 2015, 10:41:01 pm by 2ant »

Gan

  • Jr. Member
  • **
  • Posts: 98
    • View Profile
Re: Need a tiny little bit of help
« Reply #1 on: February 20, 2015, 10:15:36 pm »
The easiest way would be converting your floats to ints. That would remove trailing decimal and zeros when converting to string.

sf::Vector2f positioncurseur = curseur.getPosition();

std::string cursx = std::to_string ( (int)positioncurseur.x );
std::string cursy = std::to_string ( (int)positioncurseur.y );

title += cursx;
title += " ";
title += cursy;

2ant

  • Newbie
  • *
  • Posts: 17
    • View Profile
Re: Need a tiny little bit of help
« Reply #2 on: February 20, 2015, 10:26:47 pm »
Thank you very much Gan for your fast answer  :)

I am beginner in both c++ and sfml and i had no idea this was possible, guess i have a lot more to learn

I am testing each thing i will need for a game and for now i can check the position of my cursor directly.



How do i mark this thread as SOLVED ?

G.

  • Hero Member
  • *****
  • Posts: 1593
    • View Profile
Re: Need a tiny little bit of help
« Reply #3 on: February 20, 2015, 10:38:32 pm »
There is no built-in way to mark a thread as "solved", you have to edit the title if you want to. ;)