LWJGL绘制彩色文本到屏幕问题 [英] LWJGL Drawing colored text to the screen issue

查看:74
本文介绍了LWJGL绘制彩色文本到屏幕问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图在屏幕上显示文本,eclipse告诉我drawString方法不接受Color变量.这是我的代码

I am trying to display text on the screen and eclipse is telling me that the drawString method does not accept a Color variable. This is my code

import java.awt.Color;
import java.awt.Font;
import org.newdawn.slick.TrueTypeFont;

public class Text {

static TrueTypeFont font;

public static void drawText(int x, int y, String text) {

    Font awtFont = new Font("Terminal", Font.BOLD, 24); 
    font = new TrueTypeFont(awtFont, false);
    font.drawString(x, y, text, Color.yellow); //x, y, string to draw, color
}

}

这就是我调用该方法的方式.

And this is how I call the method.

Text.drawText(10, 10, "randomText");

是说我不允许放Color.yellow,有人可以告诉我我做错了什么吗?这是我尝试使用颜色运行时遇到的错误.请注意,如果我拿走了Color,它将在屏幕上绘制它.

It is saying that I am not allowed to put Color.yellow, can anyone please tell me what I am doing wrong. This is the error that I get if I try to run it with the color. Note that if I take away the Color it does draw it on the screen.

Exception in thread "main" java.lang.Error: Unresolved compilation problem: 
The method drawString(float, float, String, Color) in the type TrueTypeFont    
is not applicable for the arguments (int, int, String, Color)

如果有人能举一个例子,说明如何制作一个采用z,y,String和Color的方法,这将对我有很大帮助.

Also if anyone could give an example of how to make a method that takes an z, y, String, and a Color that would help me a lot.

推荐答案

您将不得不将导入更改为import org.newdawn.slick.Color或使用 font.drawString(x, y, text, org.newdawn.slick.Color.yellow);

You will either have to change your import to import org.newdawn.slick.Color or use font.drawString(x, y, text, org.newdawn.slick.Color.yellow);

这篇关于LWJGL绘制彩色文本到屏幕问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆