I am going through a tutorial book (by William Sherif) and they told me to derive a class from Hud.h and write this function prototype for DrawHud which calls DrawText.
Here is the function.
void AMyHUD::DrawHUD()
{
// call superclass DrawHUD() function first
Super::DrawHUD();
// then proceed to draw your stuff.
// we can draw lines..
DrawLine( 200, 300, 400, 500, FLinearColor::Blue );
// and we can draw text!
DrawText( "Greetings from Unreal!", FVector2D( 0, 0 ), hudFont,
FVector2D( 1, 1 ), FColor::White );
}
It gives me a bunch of errors. It looks like the DrawText function may have been changed since the book came out.
When I looked up DrawText the params did not match and I didn’t see an overloaded version that could be called in the
way he is calling it in the sample code.
This thread https://answers.unrealengine.com/questions/211230/ahuddrawtext-have-0-0-coordinates-in-center-of-the.html
seemed to suggest there are 2 versions of the function but I could not find the other in the class when searching with CTRL-F
This was all that I found in Hud.cpp
void AHUD::DrawText(FString const& Text, FLinearColor Color, float ScreenX, float ScreenY, UFont* Font, float Scale, bool bScalePosition)
{
if (IsCanvasValid_WarnIfNot())
{
if (bScalePosition)
{
ScreenX *= Scale;
ScreenY *= Scale;
}
FCanvasTextItem TextItem( FVector2D( ScreenX, ScreenY ), FText::FromString(Text), Font ? Font : GEngine->GetMediumFont(), Color );
TextItem.Scale = FVector2D( Scale, Scale );
Canvas->DrawItem( TextItem );
}
}
This takes a lot of params
I was a little confused at how to make this function call.
I haven’t worked with Fstring object before how do i pass an Fstring to a function?
Do I need to initialize the Fstring object first? or can I just pass in text like he did ( “Greetings from Unreal!”, …
How do i know what is the name of a pointer to a font, and pass that in?
Can someone please show me the right way to call this function?