HGE引擎---hgeAnimation动画精灵

3 篇文章 0 订阅

 通过hgeAnimation动画精灵类可以实现精灵动画,此处重点说一下构造函数的参数

  hgeAnimation(  HTEXTURE tex,  int nframes,  float FPS,  float x,  float y,  float w,  float h);

其中:

tex:存放动画的texture,可以通过hge->Texture_Load()加载;注意此处加载的是一个张图片,里面存放了每一帧的动画,如下图:

 

图中存放了包含20帧动画的图片。

nframes:指定tex中包含的动画帧数,上图即为20;

FPS:动画播放速度,以帧\秒计数;

x:第一帧动画的x坐标,一般为0;

y:第一帧动画的y坐标,一般为0,;

w:每一帧动画的宽度;

h:每一帧动画的高度;

以上图为例,可以如下设置参数:

hgeAnimation* g_animat = new hgeAnimation(g_tex, 20, 20, 0, 0, 139,91);

[cpp]  view plain copy
  1. #include "..\..\include\hge.h"  
  2. #include "..\..\include\hgesprite.h"  
  3. #include "..\..\include\hgeanim.h"  
  4.   
  5. HGE *hge=0;  
  6. HTEXTURE g_tex;  
  7. hgeAnimation* g_animat;  
  8.   
  9. // Handle for a sound effect  
  10. HEFFECT snd;  
  11.   
  12. // Some "gameplay" variables and constants  
  13. float x=100.0f, y=100.0f;  
  14. float dx=0.0f, dy=0.0f;  
  15.   
  16. const float speed=90;  
  17. const float friction=0.98f;  
  18.   
  19. // This function plays collision sound with  
  20. // parameters based on sprite position and speed  
  21. void boom() {  
  22.     int pan=int((x-400)/4);  
  23.     float pitch=(dx*dx+dy*dy)*0.0005f+0.2f;  
  24.     hge->Effect_PlayEx(snd,100,pan,pitch);  
  25. }  
  26.   
  27. bool FrameFunc()  
  28. {  
  29.     // Get the time elapsed since last call of FrameFunc().  
  30.     // This will help us to synchronize on different  
  31.     // machines and video modes.  
  32.     float dt=hge->Timer_GetDelta();  
  33.   
  34.     // Process keys  
  35.     if (hge->Input_GetKeyState(HGEK_ESCAPE)) return true;  
  36.     if (hge->Input_GetKeyState(HGEK_LEFT)) dx-=speed*dt;  
  37.     if (hge->Input_GetKeyState(HGEK_RIGHT)) dx+=speed*dt;  
  38.     if (hge->Input_GetKeyState(HGEK_UP)) dy-=speed*dt;  
  39.     if (hge->Input_GetKeyState(HGEK_DOWN)) dy+=speed*dt;  
  40.   
  41.     // Do some movement calculations and collision detection      
  42.     dx*=friction; dy*=friction; x+=dx; y+=dy;  
  43.     if(x>784) {x=784-(x-784);dx=-dx;boom();}  
  44.     if(x<16) {x=16+16-x;dx=-dx;boom();}  
  45.     if(y>584) {y=584-(y-584);dy=-dy;boom();}  
  46.     if(y<16) {y=16+16-y;dy=-dy;boom();}  
  47.   
  48.     g_animat->Update(dt);  
  49.   
  50.     // Continue execution  
  51.     return false;  
  52. }  
  53.   
  54. // This function will be called by HGE when  
  55. // the application window should be redrawn.  
  56. // Put your rendering code here.  
  57. bool RenderFunc()  
  58. {  
  59.     // Begin rendering quads.  
  60.     // This function must be called  
  61.     // before any actual rendering.  
  62.     hge->Gfx_BeginScene();  
  63.     hge->Gfx_Clear(0);  
  64.     // Clear screen with black color  
  65.     g_animat->Render(x, y);  
  66.   
  67.     // End rendering and update the screen  
  68.     hge->Gfx_EndScene();  
  69.   
  70.     // RenderFunc should always return false  
  71.     return false;  
  72. }  
  73.   
  74.   
  75. int WINAPI WinMain(HINSTANCEHINSTANCELPSTRint)  
  76. {  
  77.     // Get HGE interface  
  78.     hge = hgeCreate(HGE_VERSION);  
  79.   
  80.     // Set up log file, frame function, render function and window title  
  81.     hge->System_SetState(HGE_LOGFILE, "hge_tut02.log");  
  82.     hge->System_SetState(HGE_FRAMEFUNC, FrameFunc);  
  83.     hge->System_SetState(HGE_RENDERFUNC, RenderFunc);  
  84.     hge->System_SetState(HGE_TITLE, "HGE Tutorial 02 - Using input, sound and rendering");  
  85.   
  86.     // Set up video mode  
  87.     hge->System_SetState(HGE_WINDOWED, true);  
  88.     hge->System_SetState(HGE_SCREENWIDTH, 800);  
  89.     hge->System_SetState(HGE_SCREENHEIGHT, 600);  
  90.     hge->System_SetState(HGE_SCREENBPP, 32);  
  91.   
  92.     if(hge->System_Initiate())  
  93.     {  
  94.         // Load sound and texture  
  95.         snd=hge->Effect_Load("menu.wav");  
  96.         g_tex=hge->Texture_Load("fish01_01.png");  
  97.         if(!snd || !g_tex)  
  98.         {  
  99.             // If one of the data files is not found, display  
  100.             // an error message and shutdown.  
  101.             MessageBox(NULL, "Can't load MENU.WAV or PARTICLES.PNG""Error", MB_OK | MB_ICONERROR | MB_APPLMODAL);  
  102.             hge->System_Shutdown();  
  103.             hge->Release();  
  104.             return 0;  
  105.         }  
  106.   
  107.         g_animat = new hgeAnimation(g_tex, 20, 20, 0, 0, 139,91);  
  108.         //g_animat->SetColor(0xFFFFA000);  
  109.         //g_animat->SetBlendMode(BLEND_COLORMUL | BLEND_ALPHAADD | BLEND_NOZWRITE);  
  110.         g_animat->SetSpeed(10);  
  111.         g_animat->Play();  
  112.   
  113.         // Let's rock now!  
  114.         hge->System_Start();  
  115.   
  116.         // Free loaded texture and sound  
  117.         hge->Effect_Free(snd);  
  118.     }  
  119.     else MessageBox(NULL, hge->System_GetErrorMessage(), "Error", MB_OK | MB_ICONERROR | MB_SYSTEMMODAL);  
  120.   
  121.     // Clean up and shutdown  
  122.     delete g_animat;  
  123.     hge->System_Shutdown();  
  124.     hge->Release();  
  125.     return 0;  
  126. }  


HGE 1.8.1a Unicode Edition and Support Joystick中文的使用方法:1、现将现在的工程转换为UNICODE,否则会提示找不到hgeFont符号。2、在用到的字符串处使用宏TXT()进行字符处理(hge中自带的),也可声明如HGE_CHAR a[]={"hello"};方式使用3、不能使用现在的字体文件,我们先用Bitmap Font Generator (www.AngelCode.com)生成fnt字体,然后用本HGE中自带的bmfconv进行转换,生成本HGE能用的字体。手柄的使用方法:1、先生成一个指针类型的DIJOYSTATE结构,如:DIJOYSTATE js=new DIJOYSTATE; hge.h文件有此结构定义2、m_hge->System_SetState(HGE_USEJOYSTICK,true);进行标志位设置,设置为true为可用手柄。3、m_hge->System_SetState(HGE_JOYSTICKFUN,JoystickStateProxy,js); 其中JoystickStateProxy是指手柄的callback函数,相当于FrameFunc等,函数原型是void JoystickStateProxy();4、m_hge->System_SetState(HGE_JOYUPDATE,10);//更新手柄信息的速度,就是轮询时间,手柄事件的状态更新。5、m_hge->System_SetState(HGE_JOYEVENT,10);//触发事件的速度,也就是JoystickStateProxy这个函数的访问速度。这里是10毫秒触发一次要想看手柄的处理,请看我的博客文章:http://blog.csdn.net/zealczg/archive/2008/07/23/2695760.aspx( 游戏手柄(JoyStick)的延时处理 )声明:本程序的unicode 功能是国外的朋友实现的,并且还支持adobe的flash播放功能,我只是实现了手柄的接口,欢迎进行技术讨论!QQ:16535702,简单问题请勿骚扰!
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值