PDA

View Full Version : Displaying data onscreen, score for example.


danydrunk
27th Apr 2006, 03:19 AM
Iven been reading the info at udn and wikipedia, but I cant figure out what part actually prints the info onscreen. For example in the myfirst example classes theres one called: ExampleHud.uc

This .uc file has:

class ExampleHUD extends HUD;

var PlayerController PlayerOwner;
var Material HUDScoreBox;



simulated function PostBeginPlay()
{
Super.PostBeginPlay();
PlayerOwner = PlayerController(Owner);
}


function DrawHUD(canvas Canvas)
{
local Pawn PawnOwner;
local PlayerReplicationInfo PawnOwnerPRI;
local int FontSize;
local float HUDScoreScaleX, HUDScoreScaleY;
local float HUDScorePosX, HUDScorePosY;
local int Score;
local string ScoreString;
local float XL,YL;

// Get PlayerOwner
if (PlayerOwner.ViewTarget == PlayerOwner)
{
PawnOwner = PlayerOwner.Pawn;
}
else if (PlayerOwner.ViewTarget.IsA('Pawn') && Pawn(PlayerOwner.ViewTarget).Controller != None)
{
PawnOwner = Pawn(PlayerOwner.ViewTarget);
}
else if ( PlayerOwner.Pawn != None )
{
PawnOwner = PlayerOwner.Pawn;
}
else
{
PawnOwner = None;
}

// Get PlayerReplication
if ((PawnOwner != None) && (PawnOwner.Controller != None))
PawnOwnerPRI = PawnOwner.PlayerReplicationInfo;
else
PawnOwnerPRI = PlayerOwner.PlayerReplicationInfo;

//Get Font Size - (larger numbers are smaller fonts)
if ( Canvas.ClipX <= 640 )
FontSize=2;
else if ( Canvas.ClipX <= 800 )
FontSize=3;
else if ( Canvas.ClipX <= 1024 )
FontSize=2;
else if ( Canvas.ClipX <= 1280 )
FontSize=1;
else if ( Canvas.ClipX <= 1600 )
FontSize=0;
else
FontSize=0;
Canvas.Font = LoadFontStatic(FontSize);


// Draw Hud


Right now if I run it, theres a score at the right side of the screen that increases when I do the DoDance thing. What If I want to print a second score thing on the screen ? that increases when I do the fly for example ? Of all the code presented which part is actually displaying the score to the screen? Im new to this and I just need to get started, this will help me a lot thanks.

neai
27th Apr 2006, 05:38 AM
This fragment you posted doesn't draw anything.

_Lynx
27th Apr 2006, 07:07 AM
I suppose you're talking about this: http://udn.epicgames.com/Two/MyFirstHUD#My_First_HUD

the following bit of code just prepares the variables required to to script to work properly (where from the score should be taken, etc)

// Get PlayerOwner
if (PlayerOwner.ViewTarget == PlayerOwner)
{
PawnOwner = PlayerOwner.Pawn;
}
else if (PlayerOwner.ViewTarget.IsA('Pawn') && Pawn(PlayerOwner.ViewTarget).Controller != None)
{
PawnOwner = Pawn(PlayerOwner.ViewTarget);
}
else if ( PlayerOwner.Pawn != None )
{
PawnOwner = PlayerOwner.Pawn;
}
else
{
PawnOwner = None;
}

// Get PlayerReplication
if ((PawnOwner != None) && (PawnOwner.Controller != None))
PawnOwnerPRI = PawnOwner.PlayerReplicationInfo;
else
PawnOwnerPRI = PlayerOwner.PlayerReplicationInfo;

The following fragment just selects the font fitting for the current screen resolution

//Get Font Size - (larger numbers are smaller fonts)
if ( Canvas.ClipX <= 640 )
FontSize=2;
else if ( Canvas.ClipX <= 800 )
FontSize=3;
else if ( Canvas.ClipX <= 1024 )
FontSize=2;
else if ( Canvas.ClipX <= 1280 )
FontSize=1;
else if ( Canvas.ClipX <= 1600 )
FontSize=0;
else
FontSize=0;
Canvas.Font = LoadFontStatic(FontSize);

But you left out the bit that is mentioned later:
function DrawHUD(canvas Canvas)
{
...

// Draw Hud

Canvas.SetDrawColor(255,255,255);
HUDScoreScaleX = Canvas.ClipX/800;
HUDScoreScaleY = Canvas.ClipY/600;
HUDScorePosX = Canvas.ClipX - 256*HUDScoreScaleX;
HUDScorePosY = Canvas.ClipY - 128*HUDScoreScaleY;
Canvas.SetPos(HUDScorePosX, HUDScorePosY);
Canvas.DrawTileScaled(HUDScoreBox, HUDScoreScaleX, HUDScoreScaleY);

Canvas.SetDrawColor(230,240,240);
Score = PawnOwnerPRI.Score;
ScoreString = ""$Score;
Canvas.StrLen(ScoreString,XL,YL);
Canvas.SetPos(HUDScorePosX + 235*HUDScoreScaleX - XL, HUDScorePosY + 70*HUDScoreScaleY);
Canvas.DrawText(Score);
}

That's the function that actually does the drawing.

You need to have al three bits in your function. Also the defaultproperties bit should be in defaultpropertis of you class

danydrunk
27th Apr 2006, 02:12 PM
Yes I was talking about that Hud. What I havent been able to figure out is how to make the game display more than one score in on the screen. For example right now every time I press the key "G" my score increases by 1 (or more if I specify so). Lets say I want to put another score that decreases everytime I press F for example. How would I get to print two scores in the screen at the same time. So far all my atempts to make it have failed. Thanks