Welcome on MasterOf13FPS! MasterOf13FPS

Register today or sign up if you are already a member and never miss any cool content again :)

Colors together don't work

Status
Not open for further replies.

BooIMDD

Member
Joined
Apr 10, 2022
Messages
32
Reaction score
4
Points
8
Hello, does anyone know how to draw a string with two colors in the same sentence? Since currently I am trying to make a custom main menu and it does not put the colors together. Code:

Java:
String firstPart = Color.PINK + "R";
String secondPart = Color.WHITE + "aze";
String combinedString = firstPart + secondPart;
        
int stringWidth = mc.fontRendererObj.getStringWidth(combinedString);
int centerX = Math.round(width / 2f);
int centerY = Math.round(height / 2f - mc.fontRendererObj.FONT_HEIGHT / 2f);

mc.fontRendererObj.drawString(combinedString, centerX - stringWidth / 2, centerY, -1);

I believe the -1 part does something to cause this.
This is the result of this: Screenshot_3.png
 
As dirt mentioned bellow my post, you need to use Minecraft's color codes. This is what you looking for.

Java:
int stringWidth = mc.fontRendererObj.getStringWidth("Raze");
int centerX = Math.round(width / 2f);
int centerY = Math.round(height / 2f - mc.fontRendererObj.FONT_HEIGHT / 2f);

mc.fontRendererObj.drawString("R" + EnumChatFormatting.WHITE + "aze", centerX - stringWidth / 2, centerY, Color.pink.getRGB());
 
Last edited:
If you want to use Minecraft's font renderer you can use Minecraft's color codes. Otherwise, you'll have to modify the font renderer, use drawString multiple times (can't really recommend that btw) or use a custom font renderer

With -1 the color is set to white, but the color value will be overwritten if you use color codes
 
As dirt mentioned bellow my post, you need to use Minecraft's color codes. This is what you looking for.

Java:
int stringWidth = mc.fontRendererObj.getStringWidth("Raze");
int centerX = Math.round(width / 2f);
int centerY = Math.round(height / 2f - mc.fontRendererObj.FONT_HEIGHT / 2f);

mc.fontRendererObj.drawString("R" + EnumChatFormatting.WHITE + "aze", centerX - stringWidth / 2, centerY, Color.pink.getRGB());
thank you, this actually worked!
 
Status
Not open for further replies.
shape1
shape2
shape3
shape4
shape5
shape6
Back
Top