UE4 屏幕上显示文字

版权声明:本文为博主原创文章,遵循 CC 4.0 BY-SA 版权协议,转载请附上原文出处链接和本声明。
本文链接:https://blog.csdn.net/m0_37981386/article/details/83655448
// Fill out your copyright notice in the Description page of Project Settings.

#pragma once

#include "CoreMinimal.h"
#include "GameFramework/HUD.h"
#include "MyHUD.generated.h"

/**
 * 
 */
UCLASS()
class PACMAN_API AMyHUD : public AHUD
{
	GENERATED_BODY()

public:
		UPROPERTY(EditAnywhere,BluePrintReadWrite,Category=HUDFont)
		UFont* HUDFont;
	
		//每一帧都会调用
		virtual void DrawHUD() override;
};
// Fill out your copyright notice in the Description page of Project Settings.

#include "MyHUD.h"
#include "Engine/Canvas.h"

void AMyHUD::DrawHUD()
{
	DrawText(TEXT("Welcome To Game\n"),FColor::White,Canvas->SizeX/2.0f-150,Canvas->SizeY/2.0f-100,HUDFont);
}

创建基于这个类的蓝图类,然后再GameMode的HUD里面设置

展开阅读全文

进度条上显示文字

12-23

我要两个进度条上显示不同的文字,在网上找了个进度条类TextProgressCtrl,很好用,能让一个进度条显示文字。我增加了一个进度条,代码作了以下修改,但是没有任何显示,不但没有文字显示,连进度显示都没了,请高手们帮帮忙,帮我找找问题出在哪里。rnvoid CTextProgressCtrl::OnPaint() rnrn if (m_nMin >= m_nMax) rn return;rn[color=#FF0000]// CWnd *pWnd1=(CWnd*)GetDlgItem(IDC_PROGRESS1);//这样获取的指针我不知道怎么用?rn// CWnd *pWnd2=(CWnd*)GetDlgItem(IDC_PROGRESS2);//这样获取的指针我不知道怎么用?[/color]rn CRect LeftRect, RightRect,ClientRect;rn CRect rc1,rc2;rnrn[color=#FF0000]// GetClientRect(&rc1);//这样的话两个进度条显示一样的文字rn// GetClientRect(&rc2);//这样的话两个进度条显示一样的文字rnrn GetDlgItem(IDC_PROGRESS1)->GetClientRect(&rc1);//这样的话没任何显示rn GetDlgItem(IDC_PROGRESS2)->GetClientRect(&rc2);//这样的话没任何显示[/color]rn CRect *Rect1 = &rc1;rn CRect *Rect2 = &rc2;rnrn double Fraction = (double)(m_nPos - m_nMin) / ((double)(m_nMax - m_nMin));rnrn CPaintDC PaintDC(this); // device context for paintingrn CMemDC dc(&PaintDC);rnrn LeftRect = RightRect =ClientRect;rn //获取进度的大小rn LeftRect.right = LeftRect.left + (int)((LeftRect.right - LeftRect.left)*Fraction);rn dc.FillSolidRect(LeftRect, m_colFore);rnrn RightRect.left = LeftRect.right;rn dc.FillSolidRect(RightRect, m_colBk);rn UpdateData(FALSE);rn if (m_bShowText)rn rn CString str,str2;rn if (m_strText.GetLength())rn str = m_strText;rn elsern str.Format(_T("高度%d米"),_ttoi(ni1));rn str2.Format(_T("重量%d吨"),_ttoi(ni2));rn rn dc.SetBkMode(TRANSPARENT);rnrn CRgn rgn1,rgn2;rn rgn1.CreateRectRgn(Rect1->left,Rect1->top, Rect1->right, Rect1->bottom);rn dc.SelectClipRgn(&rgn1);rn //设置颜色rn dc.SetTextColor(m_colTextBk);rn //第一个进度条显示文字rn dc.DrawText(str,Rect1, DT_CENTER | DT_VCENTER | DT_SINGLELINE);rn rgn1.DeleteObject();rnrn rgn2.CreateRectRgn(Rect2->left,Rect2->top, Rect2->right, Rect2->bottom);rn dc.SelectClipRgn(&rgn2);rn //设置颜色rn dc.SetTextColor(m_colTextBk);rn //第二个进度条显示文字rn dc.DrawText(str2,Rect2, DT_CENTER | DT_VCENTER | DT_SINGLELINE);rn rgn2.DeleteObject();rn rn 论坛

没有更多推荐了,返回首页