Avec sprintf()
- include < stdlib.h>
. . .
int valeur=500; / * par exemple*/
char strvaleur[16];
sprintf(strscore,"Score : %d",score);
/ *Puis tu mets affiche sur l´ecran*/
Celle ci de vengeur marche mieux l´autre bug:
- include < SDL/SDL.h>
- include < SDL/SDL_TTF.h>
SDL_Surface *Screen;
TTF_Font *font;
/ * Fonction */
void vTexte(char *message, short x, short y, char *font_face, short font_size, Uint8 r, Uint8 g, Uint8 b)
{
SDL_Color color;
SDL_Color colorShaded;
SDL_Surface *text;
SDL_Rect Rectangle_Destination;
color.r=r;
color.g=g;
color.b=b;
font=TTF_OpenFont(font_face, font_size);
if ( ! font)
{
fprintf(stderr, " Erreur : impossible de charger la police de caractères font.ttf ( Arial) \n");
exit(2);
}
text = TTF_RenderText_Solid(font, message, color);
if ( ! text)
SDL_Quit();
Rectangle_Destination.x = x;
Rectangle_Destination.y = y;
Rectangle_Destination.w = text->w;
Rectangle_Destination.h = text->h;
SDL_BlitSurface(text, NULL, Screen, &_Destination);
SDL_FreeSurface(text);
TTF_CloseFont(font);
}
int main ( int argc, char *argv[])
{
SDL_Init(SDL_INIT_VIDEO);
TTF_Init();
Screen = SDL_SetVideoMode(320,240,16,SDL_HWSURFACE);
SDL_WM_SetCaption("TILETEST",NULL);
vTexte("J´aime la tarte aux fraises",0,0,"font.ttf",12,255,255,255);
SDL_Flip(Screen);
SDL_Delay(5000);
SDL_Quit();
return 0;
}