I’m currently on part 3.5 of the beginner fps tutorial, and am trying to write the code nessacary in order to draw the hud.
Only problem is, once i write in the code, i get about 24 errors, consisting of messages like:
>`'TileItem': undeclared identifier
>'FCanvasTileItem': undeclared identifier
>'CrossHairDrawPosition': undeclared identifier
>identifier "SE_BLEND_Translucent" is undefined
this is my HUD header file:
#include "GameFramework/HUD.h"
#include "BasicFpsHUD.generated.h"
/**
*
*/
UCLASS()
class BASICFPS_API ABasicFpsHUD : public AHUD
{
GENERATED_BODY()
protected:
//creates a pointer to a crosshair texture that will be drawn at the center of the screen.
UPROPERTY(EditAnywhere)
UTexture2D * CrosshairTexture;
public:
//calls for the HUD to be drawn.
virtual void DrawHUD() override;
};
This is my HUD cpp file:
// Fill out your copyright notice in the Description page of Project Settings.
#include "BasicFpsHUD.h"
void ABasicFpsHUD::DrawHUD()
{
Super::DrawHUD();
if (CrosshairTexture)
{
//find the center of the canvas on the HUD.
FVector2D Center(Canvas->ClipX * 0.5f, Canvas->ClipY * 0.5f);
//offset by half the dimensions so that the centre of the texture aligns with the center of the canvas.
FVector2D CrossHairDrawPosition(Center.X - (CrosshairTexture->GetSurfaceWidth() * 0.5f);
//draw crosshair at the centrepoint.
FCanvasTileItem TitleItem(CrossHairDrawPosition, CrosshairTexture->Resource, FLinearColor::White);
TileItem.BlendMode = SE_BLEND_Translucent;
Canvas->DrawItem(TileItem);
}
}
I’m thinking a missing header file, but the problem is: which one?
part of the tutorial i’m on:
https://docs.unrealengine.com/latest/INT/Programming/Tutorials/FirstPersonShooter/3/5/index.html
EDIT:
I’ve fixed the problem, there were mostly a few typos, in conjunction to too few argument types passed into CrossHairDrawPosition
the orginal code was:
FVector2D CrossHairDrawPosition(Center.X - (CrosshairTexture->GetSurfaceWidth() * 0.5f)))
instead of:
FVector2D CrossHairDrawPosition(Center.X - (CrosshairTexture->GetSurfaceWidth() * 0.5f), Center.Y - (CrosshairTexture->GetSurfaceHeight) * 0.5f);