3.学习HGE的Tutorial 03

    前面几个都是学完后再记录,这次边学边记录吧。碰到的问题都可以马上记下来:)

    首先在Visual Studio2010中配置好HGE的运行环境。把源码放进去看编译是否通过。VS提示找不到"LIBC.lib"。不过没关系,我们实际不需要这个文件。在网上搜索了一下,原因没看懂,不过找到个解决方案。只要在"项目属性"中的"链接器"栏中的"忽略特定库"中写入打不开的文件的名称,例如文中的LIBCD.lib再编译就好。

    Tutorial3教我们如何使用HGE中HGE helper classes的部分内容。应该就是精灵(sprite)、微粒(particle)、文字(font)。

    首先申明我们要用的HGE变量:

        hgeSprite* spr;

        hgeSprite* spt;//这两个hgeSprite到底是什么现在还没弄清楚。。。

        hgeFont* fnt;//控制文字用

        hgeParticleSystem* par;//控制微粒用

    在FrameFunc函数中添加以下语句,更新微粒系统:

        par->info.nEmission=(int)(dx*dx+dy*dy)*2;

        par->MoveTo(x,y);

        par->Update(dt);

    这里的info是一个很复杂的结构,里面存数了该微粒系统的信息。找了一下开发文档,里面列出了一大堆变量。在这里做下翻译工作吧,自己以后回忆的时候也快点(还是喜欢中文呀):

struct hgeParticleSystemInfo
{
  hgeSprite*  sprite;
  int         nEmission;
  float       fLifetime;

  float       fParticleLifeMin;
  float       fParticleLifeMax;

  float       fDirection;
  float       fSpread;
  bool        bRelative;

  float       fSpeedMin;
  float       fSpeedMax;

  float       fGravityMin;
  float       fGravityMax;

  float       fRadialAccelMin;
  float       fRadialAccelMax;

  float       fTangentialAccelMin;
  float       fTangentialAccelMax;

  float       fSizeStart;
  float       fSizeEnd;
  float       fSizeVar;

  float       fSpinStart;
  float       fSpinEnd;
  float       fSpinVar;

  hgeColor    colColorStart;
  hgeColor    colColorEnd;
  float       fColorVar;
  float       fAlphaVar;
};

hgeSprite*  sprite; (“精灵”?显然我还是不知道这是什么。。。。)

Pointer to a hgeSprite object to use for rendering particles. Probably, the most useful sprite's parameters here are texture, blending mode and anchor point. Besides the hgeSprite itself you may use here hgeAnimation or other classes derived from it.

指向一个用来呈现微粒的hgeSprite(精灵)对象。可能,这里sprite的最有用的参数就是texture(纹理),blending mode(绑定模式)和anchor point(定位点)。除了hgeSprite类本身,你还可以用hgeAnimation或其他hgeSprite的导出类。
int         nEmission;
Number of particles to be emitted each second. Note that maximum number of particles simultaneously allowed in one particle system is 500. If this number is exceeded, new particles wouldn't be created until some of the current particles die. The number of simultaneously alive aprticles depends on nEmission, fParticleLifeMin and fParticleLifeMax members.

每秒发射的微粒数。注意。在一个微粒系统中最多允许500个微粒同时存在。如果达到这个数目则新的微粒不会产生,直到以前的微粒消亡。同时存活的微粒数取决于nEmission,fParticleLifeMin 和 fParticleLifeMax。
float       fLifetime;
The period of time during which the particle system should emit particles (in seconds). When this amount of time is passed since call to the Fire method, the particles are no more emitted. If = -1.0 the particle system keeps emitting particles until stopped manually.

微粒系统发射微粒的时间间隔(单位为秒)。用Fire的方法发射微粒,则即使到了间隔时间,微粒也不再发射。如果取值=-1.0,则保持发射微粒,直到手动终止。
float       fParticleLifeMin;
The minimum period of lifetime for a specific particle in seconds.

一个微粒的最小生命周期,单位为秒。
float       fParticleLifeMax;The maximum period of lifetime for a specific particle in seconds.

一个微粒的最大生命周期,单位为秒。
float       fDirection; This is an angle in radians, defining the particles emitting direction.

 这是一个弧度角,定义了微粒的发射方向。
float       fSpread;

This is an angle in radians, defining the sector within which the particles are emitted. For example, if it is 0.5, the emitted particles direction lies within fDirection-0.5 and fDirection+0.5. If the fSpread is 2*pi, the fDirection parameter becomes meaningless as the whole circle is covered.

这是一个弧度角,定义了微粒的发射区域。例如,如果取值为0.5,则微粒在fDirection-0.5到fDirection+0.5的区域内发射。如果取值2*pi,则FDirection参数失去意义,因为整个圆周都被包围了。

bool        bRelative;

If true, the fDirection member is treated relatively to the current particle system movement direction. If false, the fDirection member is treated absolutely (0 means straight up).

如果为ture,则fDirection与当前微粒系统的运动方向相关。如果为false,则fDirection的方向没有相关性(0表示垂直向上)。
float       fSpeedMin;

The minimum starting speed for a specific particle in pixels per second.

某微粒的最小起始速度,单位为“像素每秒”。

float       fSpeedMax;

The maximum starting speed for a specific particle in pixels per second.

某微粒的最大起始速度,单位为“像素每秒”。
float       fGravityMin;

The minimum gravity value for a specific particle. The gravity is basically just an acceleration along the y-axis.

某微粒的最小重力。“重力”仅仅就是y方向的加速度。

float       fGravityMax;

The maximum gravity value for a specific particle. The gravity is basically just an acceleration along the y-axis.

某微粒的最大重力。“重力”仅仅就是y方向的加速度。
float       fRadialAccelMin;

The minimum value of the acceleration directed towards the particle system's center for a specific particle.

某微粒指向微粒系统中心的最小加速度。

float       fRadialAccelMax;

The maximum value of the acceleration directed towards the particle system's center for a specific particle.

某微粒指向微粒系统中心的最大加速度。
float       fTangentialAccelMin;

The minimum value of the acceleration directed perpendicularly to the radial acceleration for a specific particle.

以微粒系统中心为圆心,某微粒垂直于半径方向的最小加速度,即切向最小加速度。

float       fTangentialAccelMax;

The maximum value of the acceleration directed perpendicularly to the radial acceleration for a specific particle.

以微粒系统中心为圆心,某微粒垂直于半径方向的最大加速度,即切向最大加速度。
float       fSizeStart;

The starting scaling for a specific particle. 1.0 means the default sprite's size.

某微粒的初始大小,1.0代表默认大小。

float       fSizeEnd;

The ending scaling for a specific particle. 1.0 means the default sprite's size.

某微粒的结束大小,1.0为默认大小。

float       fSizeVar;

The starting scaling variation from 0.0 (means no variation) to 1.0 (means random variation from fSizeStart to fSizeEnd).

初始大小偏差,从0.0(表示无偏差)到1.0(表示随机偏差,取fSizeStart到fSizeEnd间的随机值)。
float       fSpinStart;

The starting spin for a specific particle in radians.

某微粒的初始旋转弧度。

float       fSpinEnd;

The ending spin for a specific particle in radians.

某微粒的结束旋转弧度。

float       fSpinVar;

The starting spin variation from 0.0 (means no variation) to 1.0 (means random variation from fSpinStart to fSpinEnd).

初始旋转弧度偏差,从0.0(表示无偏差)到1.0(表示随机偏差,取fSpinStart到fSpinEnd间的任意值)。
hgeColor    colColorStart;

The starting color and opacity for a specific particle. See hgeColor class for details. If colColorStart.r == -1 a special coloring mode is turned on: the particle system stops altering RGB of it's sprite and uses the color already set in it (the same for all particles). Only the alpha component is changed for each particle.

某微粒的初始颜色和不透明度。详情请看hgeColor class。如果colColorStart.r == -1,一个特殊的色彩模式将被开启:微粒系统停止更新颜色,并且使用内置色彩(所有微粒系统的内置色彩都一样)。仅仅只有alpha部分每个微粒系统都不一样。

hgeColor    colColorEnd;

The ending color and opacity for a specific particle. See hgeColor class for details.

某微粒的终止颜色和不透明度。详情请看hgeColor class。

float       fColorVar;

The starting color variation from 0.0 (means no variation) to 1.0 (means random variation between the starting and ending colors).

初始颜色的偏差,从0.0(无偏差)到1.0(随机偏差,取从初始色到终止色间的任意值)。

float       fAlphaVar;

The starting opacity variation from 0.0 (means no variation) to 1.0 (means random variation between the starting and ending opacities).

初始不透明度偏差,从0.0(无偏差)到1.0(随机偏差,取值为初始不透明度到终止不透明度之间的随机值)。

    呼。。。为了解释这个info,写了这么多。跟着的两个函数就好理解些了。MoveTo(x,y)将微粒系统移动到x,y。MoveTo的函数原型为void MoveTo(float x,float y,bool bMoveParticles = false);x,y为新的位置。bMoveParticles为true,则所有活动微粒都一向新位置。若bMoveParticles为 false或忽略,则仅微粒系统的发射器被移动到新位置x,y。Update(dt);更新微粒系统,dt为两次调用Update函数的时间差。

    看完这一部分我们继续(不懂的先放着吧,我也不明白)。下面在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();

    说到显示文字,这个是C风格的,对于我这种没学过C的人来说,有点怪的感觉。不过还算好懂。printf的几个参数分别为:坐标x,坐标y,对齐方式,输出字符串,输出值。其中输出值与输出字符串相对应,"%i"表示输出整型,"%d"输出十进制数,"%.2f"输出两位有效数字的float类型。除了这个函数外还有个printfb。这个函数中有两个定义宽和高的参数不知道怎么用?好像是可以定义将文本显示在某个矩形区域内。除此之外,如果纯粹输出字符串,还可以用fnt->render(x,y,HGETEXT_LEFT,"Show")函数。函数的几个参数分别为显示位置的x,y左边,对齐方式,字符串。另外,在这几个函数中,只有printfb的对齐方式是可以混合的,比如HGETEXT_LEFT | HGETEXT_MIDDLE。

    看完以上部分,终于来到主函数WinMain了。(好多啊~)

    在WinMain中首先加载了纹理tex=hge->Texture_Load("particles.png");。不知为何非要加载一张图片,明明那张png图片上面就什么都没有呀?然后增加了一个精灵:spr=new hgeSprite(tex, 96, 64, 32, 32);spr->SetColor(0xFFFFA000);spr->SetHotSpot(16,16);。看了hgeSprite的构造函数说明后,前一个问题好像有点明白了。如果hgeSprite不加载纹理图片,那么纹理效果就是默认的白色不透明底图,那么就只能看到一个小方块了。hgeSprite的构造函数各参数的意义分别如下:纹理图、Sprite在纹理中的x坐标、Sprite在纹理中的y坐标、Sprite的宽、Sprite的高。接着设置精灵颜色。HGE里的颜色以0x开头,后面只十六进制数。前两位是Alpha值(感觉就是不透明度吧?从00到FF图像逐渐就显示出来了),后两位是红色,接着两个代表黄色、最后两个代表蓝色。如果你觉得用十六进制设置挺麻烦的,也可以用ARGB(255,255,160,0)的方法,效果和用0xFFFFA000是一样的。从Alpha到RGB色彩,取值都是从0到255。最后设置热点hgeHotSpot。“热点”按我的理解就是Sprite(精灵)内部的原点,其各参数都以热点为参考。Toturial03中这里的热点设置的是Sprite的中点。

    接着在WinMain中设置字体fnt=new hgeFont("font1.fnt");。这里要加载一个字体文件,文件可以用HGE自带的字体编辑工具生成。确实它对中文的支持不好,如何让他显示中文,现在我还没有去了解。搜索其他内容是看到网上有很多关于让HGE显示中文的文章,等我需要用中文字体时再去了解吧。

    下面终于开始加载微粒系统了!

        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();

     刚才突然又有一点明白前面的问题了:)上一个精灵spr获得的是纹理particles.png中的有透明圆的部分,将不透明度设为255(最高)、色彩设为橙色(255,160,0)后,那个圆就显现出来了。现在让精灵spt获取particles.png中有透明星星的部分,将其作为微粒系统的精灵。然后设置颜色绑定模式、热点。再启动hge的微粒系统。这里的"trail.psi"是微粒系统的参数信息,可以用HGE自带的软件编辑生成他,这样就好创建微粒系统了。后面的"spt",即微粒系统发射时用的精灵,本例中为星星。最后,发射Fire()。用Fire()函数发射微粒,发射将不循环。也就是说每Fire()一次,就发射一次。这一点在翻译上面的info时已经见过了。

    其他的什么开始程序、终止释放空间,这些就不说了,应该都知道吧。

  • 0
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值