HGE教程翻譯(3)

來源:互聯網
上載者:User

 

Tutorial 03 –
使用 helper classes

 

這次我們會學習使用HGE的一些協助類。首先,包含所有需要的標頭檔並聲明HGE全域指標,大多數協助類都需要它。

 

 

 

#include <hge.h>

 

#include <hgesprite.h>
#include <hgefont.h>
#include <hgeparticle.h>
 
HGE *hge=0;

 

 

現在聲明HGE對象。

 

hgeSprite*          spr;
hgeSprite*          spt;
hgeFont*            fnt;
hgeParticleSystem*  par;
 
HTEXTURE            tex;

 

FrameFunc中我們更新粒子系統對象:我們基於精靈速度調整噴射速率並移動它到當前精靈位置。

 

  par->info.nEmission=(int)(dx*dx+dy*dy)*2;
  par->MoveTo(x,y);
  par->Update(dt);

 

RenderFunc中我們渲染所有的對象,調用它們的渲染方法。

 

  hge->Gfx_BeginScene();
  hge->Gfx_Clear(0);
  par->Render();
  spr->Render(x, y);
  fnt->printf(5, 5, HGETEXT_LEFT, "dt:%.3f/nFPS:%d",
              hge->Timer_GetDelta(), hge->Timer_GetFPS());
  hge->Gfx_EndScene();

 

WinMain函數中HGE初始化後建立HGE對象。首先設定精靈:

 

    spr=new hgeSprite(tex, 96, 64, 32, 32);
    spr->SetColor(0xFFFFA000);
    spr->SetHotSpot(16, 16);

 

接著載入字型。字型用兩個檔案描述font1.fnt
font1.png

 

    fnt=new hgeFont("font1.fnt");

 

建立粒子系統和精靈。

 

    spt=new hgeSprite(tex, 32, 32, 32, 32);
    spt->SetBlendMode(
              BLEND_COLORMUL | BLEND_ALPHAADD | BLEND_NOZWRITE);
    spt->SetHotSpot(16, 16);
    par=new hgeParticleSystem("trail.psi", spt);
    par->Fire();

 

現在所有對象建立完畢開始遊戲迴圈。

 

    hge->System_Start();

 

遊戲迴圈結束我們刪除所有的HGE對象。

 

    delete par;
    delete fnt;
    delete spt;
    delete spr;

 

這個程式的結束值和先前的樣本是一樣的。 

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.