LWJGL Drawing colored text to the screen issue

北城余情 提交于 2019-12-11 10:53:55

问题


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");

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)

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.


回答1:


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);



来源:https://stackoverflow.com/questions/30740018/lwjgl-drawing-colored-text-to-the-screen-issue

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!