zoukankan      html  css  js  c++  java
  • 制作HUD


     1. HUD不仅仅能提供基本的显示信息给玩家,例如玩家的生命值等。在IOS系统甚至都牵扯到游戏的基本操作。

    class AntHUD extends UDKHUD;

    var float PlayerNameScale;
    var Font MyFont;


    function DrawHUD()
    {
    var vector2D TextSize;
    super.DrawHUD();

    Canvas.Font=MyFont;
    Canvas.DrawColorStruct(WhiteColor); //同样可以使用Canvas.DrawColor(255,255,255,255);来显示
    Canvas.TextSize(PlayerOwner.Pawn.Health,TextSize.X,TextSize.Y); //文本的区域大小
    Canvas.SetPos(TextSize.X*PlayerNameScale/ratioX,TextSize.Y*PlayerNameScale/ratioY); //文本的位置
    Canvas.DrawText(PlayerOwner.Pawn.Health,,PlayerNameScale/RatioX,PlayerNameScale/RatioY); //文本的字体大小
    }

    defaultproperties
    {
    PlayerNameScale=0.25
    MyFont="UI_Fonts.MultiFonts.MF_HudLarge"
    }

       以上可以输出文字。

     

    2. Canvas.DrawRect(rectX,rectY);     //能绘制矩形,参数分别为长度和宽度

      绘制矩形列表,这可以用来表示血槽

      

    function DrawBar(string title,float value,float MaxValue,int x,int y,int r,int g,int b)
    {
    local int PosX; //从哪里开始绘制
    local int BarSizeX; //绘制的长度

    PosX=x;
    BarSize=200*FMin(value/MaxValue,1); //200只不过是个调节长度值

    canvas.SetPos(PosX,Y);
    canvas.DrawColor(255,255,255,80); //画一个白框
    canvas.DrawRect(200-BarSizeX,12); //当红色槽子没有时生成底部

    if(!PlayerOwner.IsDead()) //没死才渲染,死了就不渲染
    {
    canvas.SetPos(PosX,Y);
    canvas.DrawColor(R,G,B,80); //Draw Blood rect
    canvas.DrawRect(BarSizeX,12);
    }
    }

      然后将DrawBar写到DrawHUD函数中即可。

    3.绘制Texture方法

    DrawTile函数是专门用来绘制贴图的方法,参数如下:

    /** 
    * Draws a texture to an axis-aligned quad at CurX,CurY.
    *
    * @param Tex - The texture to render.
    * @param XL - The width of the quad in pixels.
    * @param YL - The height of the quad in pixels.
    * @param U - The U coordinate of the quad's upper left corner, in normalized coordinates.
    * @param V - The V coordinate of the quad's upper left corner, in normalized coordinates.
    * @param UL - The range of U coordinates which is mapped to the quad.
    * @param VL - The range of V coordinates which is mapped to the quad.
    * @param LColor - Color to colorize this texture.
    * @param bClipTile - Whether to clip the texture (FALSE by default).
    */

    DrawTile(tex,XL,YL,U,V,UL,VL);

    说明一下tex为要画的贴图,XL,YL分别为横纵方向的缩放(默认的大小写成和UL和VL一样),UV是从图像上左上角算起的坐标。如下图所示:

    对于上图有以下方式渲染:

    var Texture2D DefaultTexture;

    CursorTexture=Texture2D'UI_HUD.HUD.UI_HUD_BaseA' 

    以下方法渲染图片

    Canvas.DrawTile(CursorTexture, 50 , 50, 215, 100, 50,50);

    如果要把图片渲染为两倍,则使用以下方法:

    Canvas.DrawTile(CursorTexture, 50*2 , 50*2, 215, 100, 50,50); 

    当然这只不过是一个基本的参数说明,实际绘制将使用下面的方法。

    4. 以下方法来实现屏幕上绘制一张Texture

    function DrawIconStretch(CanvasIcon Icon,float x,float y,optional float ScaleX,optional float ScaleY)

    {

      Canvas.SetPos(X,Y);

      DrawTileStrecth(Icon.texture,Abs(Icon)*ScaleX,Abs(Icon)*ScaleY,Icon.x,Icon.y,Icon.Ul,Icon.Vl,,true,true);
    }

    var Texture2D DefaultTexture;

    var CanvasIcon CrossIcon; 

    CrossIcon=(Texture2D="...",U=215,V=100,UL=50,VL=50)

    function DrawHUD()

    {

      DrawIconStretch(CrossIcon,300,300,1,1);
    }

     


     

       

  • 相关阅读:
    MISC | ctfshow 31
    010editor 没有分块高亮显示了
    BUUCTF | [网鼎杯 2020 朱雀组]phpweb
    python2与python3共存后,如何使用
    kali2020 装不上docker
    php代码审计整理
    [MRCTF2020]Ezpop
    kali没有tcptraceroute如何安装
    [BUUCTF] 真的很杂
    【弱网测试】备份弱网测试相关数据
  • 原文地址:https://www.cnblogs.com/NEOCSL/p/2380341.html
Copyright © 2011-2022 走看看