Jump to content

Recommended Posts

Posted

Alright, so I am trying to render some text onto the player HUD. It renders just fine, except the position changes when I go into fullscreen from a windowed screen.

 

Windowed:

 

Fullscreen:

 

Here is where I render it:

@SubscribeEvent
public void onRenderHUD(RenderGameOverlayEvent event) {
	Minecraft mc = Minecraft.getMinecraft();

	ExtendedPlayer props = ExtendedPlayer.get(mc.thePlayer);

	if(event.isCancelable() || event.type != ElementType.EXPERIENCE) {
		return;
	}

	int xPos = event.resolution.getScaledWidth() / 2 + 6;
	int yPos = event.resolution.getScaledHeight() / 2 - 6;

	mc.fontRendererObj.drawString(I18n.format(props.getCurrentWeight() + "/" + props.getMaxWeight(), new Object[0]), xPos, yPos, (props.isOverEncumbered() ? Color.RED.darker().getRGB() : 4210752));
}

I am not a cat. I know my profile picture is sexy and amazing beyond anything you could imagine but my cat like features only persist in my fierce eyes. I might be a cat.

Posted

I posted this and realized my mistake then changed it. :P I'll change the post though as to not confuse. xD

I am not a cat. I know my profile picture is sexy and amazing beyond anything you could imagine but my cat like features only persist in my fierce eyes. I might be a cat.

Posted

For the y-axis, resolutionScaled.getScaledHeight() is always the bottom of the screen, and the vanilla hotbar slots are 18 pixels tall, so (height - 18 - fontHeight) will put text right above them (vertically). Dividing it by 2 will put you relative to the center of the screen, which you don't want if you are trying to stay relative to the hotbar.

 

Horizontally, resolutionScaled.getScaledWidth() / 2 will always be relative to the center, with your text flowing to the right. This should be fine, subtracting some amount to move it further left above the hotbar.

 

It looks like you have a HUGE difference in screen resolution between those 2 images, btw, though the positions shown in either image still don't look right for the values you have in your code.

 

One thing to note: RenderGameOverlayEvent has both a Pre and a Post - choose Pre if you want to cancel the event, or Post if you just want to render, e.g.:

@SubscribeEvent
public void onRenderExperienceBar(RenderGameOverlayEvent.Post event) {
if (event.type != RenderGameOverlayEvent.ElementType.EXPERIENCE) {
	return; // limit the rendering to one ElementType, otherwise it will render LOTS of times each frame
}
// do your rendering here
}

Posted

Seems my problem was not using the Post of RenderGameOverlayEvent. :P Thank you coolAlias!

I am not a cat. I know my profile picture is sexy and amazing beyond anything you could imagine but my cat like features only persist in my fierce eyes. I might be a cat.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Unfortunately, your content contains terms that we do not allow. Please edit your content to remove the highlighted words below.
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

By using this site, you agree to our Terms of Use.