Scoring the Tile in HUD C++

challenge: Scoring the code in C++

// Get GameMode for GetScore() function
GameMode = Cast<AInfiniteTerrainGameMode>(GetWorld()->GetAuthGameMode());


// Get Score and Convert to String
int32 Score = GameMode->GetScore();
FString ScoreString = FString::FromInt(Score);   


// Set Text Color
FLinearColor TextColor = FLinearColor(0.2f, 0.5f, 0.5f);


// Get and then Set Font from Unreal Editor
UObject* obj_ptr = StaticLoadObject(UFont::StaticClass(), NULL, TEXT("/Game/DYNAMIC/UI/Font/dreamorp_Font"));
UFont *TextFont = Cast<UFont>(obj_ptr);
if (!ensure(TextFont)) { UE_LOG(LogTemp, Warning, TEXT("font is NULL")); return; }

// Set Box size
float XL = 150.f;
float YL = 180.f;
Canvas->TextSize(TextFont, ScoreString, XL, YL);

// Set Posiion of Box in Screen
const float X = Canvas->ClipX * 0.93f + XL; // / 2.0f + ScorePosition.X;
const float Y = Canvas->ClipY * 0.1f + YL; // / 2.0f + ScorePosition.Y;


 // Create Text Content
FCanvasTextItem TextItem(FVector2D(X, Y), FText::FromString(ScoreString), TextFont, FLinearColor(TextColor));

TextItem.bOutlined = true;
TextItem.OutlineColor = FLinearColor(0.5, 0.4, 0.7);


// Set Scale of Text Content
FVector2D FontScale(7.0f, 7.0f);
//TextItem.EnableShadow(FLinearColor::Black, FVector2D{ 2 * FontScale.X, 2 * FontScale.Y });
TextItem.Scale = FontScale;

// Draw the Text
Canvas->DrawItem(TextItem);

Privacy & Terms