gpt4 book ai didi

c - graphics.h C 中 outtextxy 的负 x 值

转载 作者:太空宇宙 更新时间:2023-11-04 03:56:53 24 4
gpt4 key购买 nike

我制作了一款使用 graphics.h 的游戏。我使用 while 循环来创建屏幕输出,因此下例中的 x1 值始终减少 5。这意味着我一直在创建游戏的所有屏幕,除非 while 循环继续,玩家只会看到他所在的屏幕部分。这显然是非常低效的,所以我想知道是否有人有以更有效的方式执行此操作的提示。我还有一个更具体的问题……outtextxy 不允许负 x 值,意思是

outtextxy(-10,400,"text that is long enough that should be shown on screen even though it starts before screen beginning");

没有出现在屏幕上,所以我的代码是:

outtextxy(x1+301,400,"Use 'd' to duck");

它会在游戏中的屏幕通过之前停止打印到屏幕,即 x 值变为负数的那一刻,而不是当结束字母的 x 值通过时,就像我希望的那样。

最佳答案

您需要clip输出。像这样包装 outtextxy(您可能需要调整参数和返回值以匹配 outtextxy)。我假设您使用的是固定宽度的字体。

在 x 坐标中剪切文本类似于这样:

int clippedouttext(int x, int y, char *text) {
const int CHAR_WIDTH = 8; /* Replace 8 by actual character width */
if (text == NULL || *text = '\0') { return 0; } /* No text was submitted */
while (x < 0) {
x += CHAR_WIDTH;
++text;
if (*text == `\0`) { return 0; } /* The text is outside the viewport. */
}
return outtextxy(x, y, text);
}

关于c - graphics.h C 中 outtextxy 的负 x 值,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15612831/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com