HGE学习笔记,显示图像与播放声音

作者在 2012-04-07 12:26:45 发布以下内容
#include "hge.h"
#include "hgesprite.h"

const int screen_width = 535;
const int screen_height = 656;

HGE *hge = NULL;

hgeSprite *spr;//声明一个精灵类指针;

HTEXTURE tex;//定义一个纹理对象;

HEFFECT snd;//声音;

//逻辑函数;
bool FrameFunc()
{
    hge->Effect_PlayEx(snd,50);
    return false;
}
//绘制和渲染函数;
bool RenderFunc()
{
    hge->Gfx_BeginScene();
    hge->Gfx_Clear(0xFF3D59AB);
    spr->Render(0.0,0.0);
    hge->Gfx_EndScene();
    return false;
}

int WINAPI WinMain(HINSTANCE hInstance,
                   HINSTANCE hPrevInstance,
                   LPSTR lpCmdLine,
                   int nCmdShow
                   )
{
    
//    MessageBox(NULL,"MyHGEDemo","Title",0);
    hge = hgeCreate(HGE_VERSION);//创建hge接口;
    
//窗口的宽和高;
    hge->System_SetState(HGE_SCREENWIDTH,screen_width);
    hge->System_SetState(HGE_SCREENHEIGHT,screen_height);
    //设置逻辑函数;
    hge->System_SetState(HGE_FRAMEFUNC,FrameFunc);
    hge->System_SetState(HGE_RENDERFUNC,RenderFunc);
    //窗口标题;
    hge->System_SetState(HGE_TITLE,"我的HGE窗口");
    //使用窗口模式;
    hge->System_SetState(HGE_WINDOWED,true);
    //是否使用声音;
    hge->System_SetState(HGE_USESOUND,true);

    hge->System_SetState(HGE_SHOWSPLASH,false);
    
    //初始化成功;
    if (hge->System_Initiate())
    {
        tex = hge->Texture_Load("tanke2.jpg");
        if (!tex)
        {
            MessageBox(NULL,"Load image error!","Error",0);
        }
        spr = new hgeSprite(tex,0,0,535,656);
        
        snd = hge->Effect_Load("020music.mp3");
        if (!snd)
        {
            MessageBox(NULL,"Load sound error!","Error",0);
        }

        hge->System_Start();
    }
    

    //释放资源;
    hge->Effect_Free(snd);
    hge->Texture_Free(tex);
    delete spr;
    hge->System_Shutdown();
    hge->Release();
    return 0;
}
 
hge | 阅读 1707 次
文章评论,共0条
游客请输入验证码
浏览5869次
最新评论