Chapter 7
195
- With all of our drawing functions for the bar in place, we need a way to align
it on screen.
/**
- Returns corrected HUD position based on current res.
- @Param Position Default position based on 1024x768 res
- @Param Width Width of image based on 1024x768
- @Param Height Height of image based on 1024x768
- @returns FinalPOS
**/
function Vector2D CorrectedHudPOS(vector2D Position, float Width,
float Height)
{
local vector2D FinalPos;
FinalPos.X = (Position.X < 0)? Canvas.ClipX -
(Position.X * ResScaleY) - (Width * ResScaleY) :
Position.X * ResScaleY;
FinalPos.Y = (Position.Y < 0)? Canvas.ClipY -
(Position.Y * ResScaleY) - (Height * ResScaleY) :
Position.Y * ResScaleY;
return FinalPos;
}
CorrectedHudPOS() verifies that our HUD looks the same regardless of resolution.
Now that UDK is supported on a number of mobile devices, this is more necessary than
ever. Console developers generally only have a handful of resolutions to contend with,
while iOS and Android developers now add a whole new set of problems into the mix.
This function scales the location of our HUD based on the resolution and handles
that sticky math for us.
- With our functions out of the way, the only thing left to do in this class is to add the
default properties.
DefaultProperties
{
// Texture for HP bar
BarTexture=Texture2D'UI_HUD.HUD.UI_HUD_BaseA'
/** Hit Points */
/** Corner Position of bar. + / - to X / Y changes which
corner it is in */
HPPosition=(X=0,Y=1)
// Coords for the HP bar
BarCoords=(U=277,V=494,UL=4,VL=13)
}