-1

I am programming Pac-man in C++ SDL and I want to show the score on the screen.

My score is a class:

entite.score += 10;

entite.scoreTotal += 10;

and then I call them to the main.

To write a texte I use this function :

afficherTexte(screenSurface, "Score", 255, 255, 255, "./Polices/crackman.ttf", 30, 30, 540);

but I don't know how to show on screen variables of the type class.

genpfault
  • 51,148
  • 11
  • 85
  • 139
Mily
  • 7
  • 2
  • Are you print the score in orthographic projection? – mr5 May 18 '18 at 04:40
  • Vague. To my understanding you can print static text, but you don't know how to do that with variable value, is that right? – keltar May 18 '18 at 13:16

1 Answers1

0

You need to convert the int to a string in order to call it in that method.

Here's an example of the conversion just using cout.

#include <iostream>
#include <string>

int main()
{
    int x = 42;
    std::string y;
    y  = std::to_string(x);
    std::cout << y << std::endl;
    return 0;
}

Output is 42

However you may run into a MinGW or G++ bug while compiling that, fix here.

When you call afficherTexte(screenSurface, "Score", 255, 255, 255, "./Polices/crackman.ttf", 30, 30, 540); just replace the Score with y, as I called it in my example.