HGE:Tutorials:Fonts
来源:互联网 发布:数据挖掘32个经典案例 编辑:程序博客网 时间:2024/06/08 14:43
Fonts
hgeFont是Hge的辅助类,用来渲染 bitmap 字体. 有两个必须的组件来实现该功能:
- Font bitmap file:图像文件(通常是png文件),用来存储每一个字符。
- Font description file:描述文件,定义每一个字符在图像文件中的位置,具体的定义细节你可以参考如下连接: Font description files in HGE
定义Fonts在res文件中
此处有hge默认的字体图像: Media:HGE_font1.png [link appears broken...however they can be obtained from the HGE website]
该字体文件的描述文件: Media:HGE_font1.fnt
将两个文件 font1.png and font1.fnt,放置在程序的同一目录下。
定义一个字体文件,注意使用字体描述文件来定义,而不是bitmap文件!!!!
Font font1{ filename=font1.fnt}
显示字体文本
#include <hgefont.h> hgeFont* font1;
WinMain函数中加入:
font1 = myRes->GetFont("font1");
渲染字体,用 hgeFont的 Render() 或者 printf() 函数都可以。
Render()函数带有4个参数:(x,y)的屏幕坐标,你要显示的文本, 对齐方式. 对齐方式包括: HGETEXT_LEFT, HGETEXT_RIGHT, HGETEXT_CENTER, . printf()函数参见 : printf statement
在FrameFunc函数体中加入:
font1->SetScale(1.0); //set text size to normalfont1->SetColor(ARGB(255,0,0,0)); //set color of text to blackfont1->Render(5, 5, "This is some text"); //render text at coordinates 5, 5int someNumber = 50;font1->SetScale(2.0); //set text size to twice its normal sizefont1->printf(5, 30, "Here is a number: %d", someNumber); //render text using printf-style formatting
整个的FrameFunc函数如下:
bool FrameFunc(){ float dt=hge->Timer_GetDelta(); //get the time since the last call to FrameFunc star->Update(dt); //update the animation hge->Gfx_BeginScene(); hge->Gfx_Clear(0); //clear the screen, filling it with black bgSprite->RenderStretch(0, 0, 800, 600); //render the background sprite stretched playerSprite->Render(200, 200); //render the player sprite star->Render(400, 300); //render the animation of a star font1->SetScale(1.0); //set text size to normal font1->SetColor(ARGB(255,0,0,0)); //set color of text to black font1->Render(5, 5, HGETEXT_LEFT, "This is some text"); //render text at coordinates 5, 5 int someNumber = 50; font1->SetScale(2.0); //set text size to twice its normal size font1->printf(5, 30, HGETEXT_LEFT, "Here is a number: %d", someNumber); //render text using printf-style formatting hge->Gfx_EndScene(); return false;}
- HGE:Tutorials:Fonts
- HGE:Tutorials:Video
- HGE:Tutorials:Input
- HGE:Tutorials:Particle Effects
- HGE:Tutorials:Random Numbers
- HGE:Tutorials:Rectangle Class
- HGE:Tutorials:Simple Game
- <考古笔记>hge游戏引擎(一)Tutorials
- fonts
- Tutorials
- Tutorials
- Tutorials
- Tutorials
- Tutorials
- HGE 丢失hge.dll
- color&fonts
- Fonts (1)
- Bitmap Fonts
- Effective C++学习心得(续)
- 高效能人士的七个习惯之积极主动
- PB中数据窗口的函数小结
- MCU概念
- PreparedStatement与Statement
- HGE:Tutorials:Fonts
- 职场金律
- 对下一步工作的思考 和 临时分工
- Oracle 唯一 约束(unique constraint) 与 索引(index) 关系说明
- ROM, RAM, SRAM, DRAM, EPROM, EEPROM, Flash, NOR Flash, NAND Flash关系
- 如何成为一个合格的职场人
- DSP概念
- Oracle:Rank,Dense_Rank,Row_Number比较
- 微处理器, 中央处理器的概念