简体   繁体   English

Allegro 5 al_draw_textf()

[英]Allegro 5 al_draw_textf()

I have been looking how to draw string on the screen using Allergo 5 and knew about al_draw-textf() which was said to work like printf() in stdio.h . 我一直在寻找如何使用Allergo 5在屏幕上绘制字符串,并且知道al_draw-textf() ,据说它在stdio.h中像printf()一样工作。 So when I want to print a string on console window I write printf("%s" , string_name); 因此,当我想在控制台窗口上打印字符串时,我写了printf("%s" , string_name); But when I write this 但是当我写这个

al_draw_textf(font , al_map_rgb(255 , 255 , 0) , 250 , 250 , ALLEGRO_ALIGN_LEFT , "%s" , num); al_draw_textf(font,al_map_rgb(255,255,0),250,250,ALLEGRO_ALIGN_LEFT,“%s”,num);

there is nothing written on the display . 显示屏上没有任何内容。 When I change the %s to %d and the num variable to an integer it draws the value of the num correctly . 当我将%s更改为%d并将num变量更改为整数时,它将正确绘制num的值。 Am I doing something not correctly or this function is only used to draw integer variables ? 我是在做一些不正确的事情,还是此函数仅用于绘制整数变量?

If all you want to do is draw a constant string without formatting, just use: 如果您只想绘制一个不带格式的常量字符串,请使用:

void al_draw_text(const ALLEGRO_FONT *font,
   ALLEGRO_COLOR color, float x, float y, int flags,
   char const *text)

Although what you are doing should still work, so if the above doesn't help, you'll need to post more code. 尽管您的操作仍然可以正常工作,但是如果以上操作没有帮助,则需要发布更多代码。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM