我试图将 drawString 的文本输出集中在程序中的 X 坐标上。我正在尝试获取窗口的宽度并除以两个以获得中心但无济于事。这是我的代码:
package net.minecraft.src;
import java.awt.Color;
import java.awt.FontMetrics;
import org.lwjgl.input.Keyboard;
import java.text.NumberFormat;
import java.util.ArrayList;
import java.util.Iterator;
import java.util.Random;
import net.minecraft.client.Minecraft;
import org.lwjgl.opengl.GL11;
import org.lwjgl.opengl.GL12;
public class GuiIngame extends Gui
{
//lots of other code here
NumberFormat nf = NumberFormat.getInstance();
nf.setMaximumFractionDigits(0);
String xCords = nf.format(mc.thePlayer.posX);
String yCords = nf.format(mc.thePlayer.posY);
String zCords = nf.format(mc.thePlayer.posZ);
drawString(fontrenderer, (new StringBuilder()).append("X: ").append(xCords).toString(), 20, 2, 0xe0e0e0);
drawString(fontrenderer, (new StringBuilder()).append("Y: ").append(xCords).toString(), 40, 2, 0xe0e0e0);
drawString(fontrenderer, (new StringBuilder()).append("Z: ").append(xCords).toString(), 60, 2, 0xe0e0e0);
}
它只需要以 x 轴为中心。