HGE 的Resource Manager

来源:互联网 发布:淘宝点评赚钱 编辑:程序博客网 时间:2024/04/28 01:31
HGE 的Resource Manager


Resource Manager

The resource manager is a way of defining textures, sprites, sounds, and other items that your application makes use of. hgeresourceManager is an HGE helper class that automates creation of complex resource objects and their management in memory.

资源管理器是一种定义纹理,精灵,声音,以及其他被你的应用程序使用的资源的方法。

hgeResourceManager是HGE的扩展类,它使得创建各种复杂的资源以及管理各种资源自动化。

Resource Script files (资源脚本文件)

Resource script files are used with hgeResourceManager helper class to define complex resources. They are just plain text files containing resource definitions. A resource script file consists of commands separated by whitespace characters ('/t', '/n', '/r' or ' '). If a semicolon (';') is encountered, the rest of the line is treated as a comment and is not parsed. All the commands and names are case sensitive.

资源脚本文件和hgeResourceManager扩展类一起使用来定义复杂的资源。资源脚本文件是包含了资源定义的纯文本文件。一个资源脚本文件由被空格字符('/t', '/n', '/r' 或 ' ' )分开的命令组成。而分号(“;”)被用做注释,它后面的一行字符都将被认为是注释,而不被引擎解释。所有的命令以及名字都是大小写敏感的。

The command formate is:

命令格式为:

ResourceType ResourceName [ : BaseResourceName ]
{
Parameter1=Value1
Parameter2=Value2
...
ParameterN=ValueN
}
Example: specifying a texture

一个指定了纹理的例子:
Texture myTexture
{
file=picture1.png
}
For now, just create a blank text file named resource.res and place it in the same directory as the main.cpp file. Using the Resource Manager

现在创建一个名为resource.。res的空白文件,然后写入以上内容,并把这个文件放到与main.cpp相同目录下。使用资源管理器:
To use the resource manager, include the hgeresource.h file and declare myRes, which will be used when we need to access our resources:
要使用资源管理器,需要包含 hgeresource.h 文件,并定义myRes对象:

#include

hgeResourceManager *myRes;

Inside WinMain(), but before the hge->System_Start() call, we initialize myRes with the name of the resource file we will be using.

在WinMain()函数里,在 hge->System_Start()前我们用刚才写的那个资源脚本文件初始化 myRes 对象。

myRes = new hgeResourceManager("resource.res");

程序退出时删除myRes对象即可。
我的总结:

例如要使用纹理,你可以这样定义:

Texture back

{

filename=back.jpg

}



把这个定义放到一个res文件里,例如:resource.res。然后在程序里可以这样使用这个纹理:

HTEXTURE backTx;

hgeResourceManager *resMgr = new hgeResourceManager( "resource.res" );

backTx = resMgr->GetTexture( “back” );

同理,要使用精灵,就可以这样做:

在res文件了里

Texture sheet

{

filename=sheet.png

}

Sprite playerSprite

{

texture=sheet

rect=0, 0, 64, 64

}

因为sprite 需要为其指定纹理,所以其参数texture=sheet,sheet是res文件中之前定义的纹理。

然后在程序里:

hgeSprite *sprite ;

hgeResourceManager *resMgr = new hgeResourceManager( “resource.res”);

sprite = resMgr->GetSprite( “playerSprite” );

然后就可以完全地使用sprite了。