Preface:
First of all, before creating the person's blood strip, I need to declare the following points:
1. The blood bar of the character is a simple form of backspace, not a continuous progress bar.
2. The production of the blood strip is purely completed by rapid development. If it does not reach the level of detail, the experts can bypass it.
On the premise of the above two points, I will give a rough introduction to the process of using cegui to create blood strips in ogre.
First of all, the Avatar uses an image of my favorite full-time Hunter, qishi:
Then, in combination with the purple color, I chose a purple blood cell:
After having a blood stripe unit (I call it Zixing here), I spliced 11 images using image production tools,
From 0-star to 10-star, the name is purple_x.jpg (X indicates the number of purple stars ).
A picture of a 9-star purple star:
So far, after the materials are ready, I started to complete my program in ogre,
Below is the code for completing the image, text, and window drawing. I encapsulate it in a function:
(Cegui is 0.8.3)
// Compute [createsrcbloodshowwindow () function] examples // Desc: Create the window for displaying the master model's blood volume // define void ninthcegui: createsrcbloodshowwindow (float ratio/* = 1.6f */) {cegui: windowmanager & wmgr = cegui: windowmanager: getsingleton (); // create backspace blood records, blood volume, and profile pictures. m_bloodw = wmgr. createwindow ("windowslook/staticimage", "beyond/blood"); m_bloodnumw = wmgr. createwindow ("ogretray/statictext", "beyond/bloodnum"); cegui: window * head = wmgr. createwindow ("windowslook/staticimage", "beyond/head"); // load the image cegui: imagemanager: getsingleton (). addfromimagefile ("head", "head.jpg"); For (size_t I = 0; I <= 10; I ++) cegui: imagemanager: getsingleton (). addfromimagefile ("Purple" + ogre: stringconverter: tostring (I), "Purple _" + ogre: stringconverter: tostring (I) + ". jpg "); // Add the image to the window myceguisystem: getsingletonptr ()-> addimagetowindow (Head," head ", 0.02f/ratio, 0.02f, 0.1f/ratio, 0.1f); values: getsingletonptr ()-> addimagetowindow (m_bloodw, "purple10", 0.12f/ratio, 0.085f, 0.25f/ratio, 0.035f); values-> setarea (cegui :: udim (0.13f/ratio, 0), cegui: udim (0.05f, 0), cegui: udim (0.2f/ratio, 0), cegui: udim (0.04f, 0); // remove the text border and background of the heap window, and set the text to purple m_bloodnumw-> setproperty ("frameenabled", "false "); m_bloodnumw-> setproperty ("backgroundenabled", "false"); m_bloodnumw-> setproperty ("textcolours", "TL: ffffaaff TR: ffffaaff Bl: ffffaaff BR: ffffaaff "); // Add to the root window cegui: window * root = cegui: System: getsingleton (). getdefaguguicontext (). getrootwindow (); root-> addchild (m_bloodw); root-> addchild (m_bloodnumw); root-> addchild (head );}
I show the specific value of the blood volume above the blood strip. in order to match the overall color, set it to light purple,
The following are the details of addfromimagefile and addimagetowindow of myceguisystem, which I have encapsulated myself:
// Addfromimagefile () function] else // Desc: add an image // define void myceguisystem: addfromimagefile (const cegui: string & imagename, const cegui :: string & filename) {cegui: imagemanager: getsingleton (). addfromimagefile (imagename, filename );}
// Define [createimagewindow () function] functions // Desc: Create a static image window // define void myceguisystem: addimagetowindow (cegui: window * window, const cegui :: string & imagename, float left/* = 0.0f */, float top/* = 0.0f */, float width/* = 1.0f */, float height/* = 1.0f */) {window-> setarea (cegui: udim (left, 0.0f), cegui: udim (top, 0.0f), cegui: udim (width, 0.0f), cegui :: udim (height, 0.0f); window-> setproperty ("image", imagename );}
The reason why the createsrcbloodshoww () function uses the ratio parameter is because it is adapted to the changes in the game window, so that the Avatar and blood strip are not deformed,
Ratio = window width/window height.
Bytes -------------------------------------------------------------------------------------------------------------------------------
The profile picture, blood volume, and blood cord creation section are described. Next, we will introduce the blood volume of the person and the updated Display Section of the blood cord,
The core code of framerenderingqueued () is as follows:
// Update m_ninthcegui-> getsrcbloodnumw ()-> settext ("Blood:" + ogre: stringconverter: tostring (INT) m_hp )); static int ibloodpart =-1; int I = 0; while (1) {If (m_hp <= I * model_max_blood/10) {If (ibloodpart! = I) {m_ninthcegui-> getsrcbloodw ()-> setproperty ("image", "Purple" + ogre: stringconverter: tostring (I); ibloodpart = I ;} elsebreak;} else {I ++; if (I> 10) break ;}}
With the above Code, the blood volume of the person will be updated in each frame. Once the blood is regressed, the amount of blood is increased every X/10 (x = 0, 1, 2... 9) The border is automatically updated and displayed.
Finally, I have attached a complete picture for your understanding:
Zookeeper