Health Bar

If you are a new Irrlicht Engine user, and have a newbie-question, this is the forum for you. You may also post general programming questions here.
Post Reply
Vintige
Posts: 11
Joined: Tue Nov 13, 2007 10:57 am

Health Bar

Post by Vintige »

Hi this is the code for my health bar but it isnt showing up, there arnt any errrors though. Can you please help?

Code: Select all

 ICameraSceneNode* camera = 0;
ISceneNode* node = 0;
int health = 100;



class MyEventReceiver : public IEventReceiver 
{ 
public: 
   virtual bool OnEvent(SEvent event) 
   { 
      if(node != 0 && event.EventType == EET_KEY_INPUT_EVENT && 
         !event.KeyInput.PressedDown) 
      { 
         switch(event.KeyInput.Key) 
         { 
         case KEY_KEY_A: 
            { 
               health -= 1;break; 
            } 
         case KEY_KEY_S: 
            { 
               health += 1;break; 
            } 
         } 
      } 
      if(camera) 
      { 
         return camera->OnEvent(event); 
      } 

      return false; 
   } 
};
Thankyou
Acki
Posts: 3496
Joined: Tue Jun 29, 2004 12:04 am
Location: Nobody's Place (Venlo NL)
Contact:

Post by Acki »

no, this is just the code for the health not for the health bar !!! ;)
show us the code where you draw the bar...
while(!asleep) sheep++;
IrrExtensions:Image
http://abusoft.g0dsoft.com
try Stendhal a MORPG written in Java
Vintige
Posts: 11
Joined: Tue Nov 13, 2007 10:57 am

Post by Vintige »

sorry here it is

Code: Select all

driver->draw2DRectangle(SColor(255,255,0,0), rect<s32>(10,10,health+10,20));
Acki
Posts: 3496
Joined: Tue Jun 29, 2004 12:04 am
Location: Nobody's Place (Venlo NL)
Contact:

Post by Acki »

well, this line seems to be correct...
maybe you didn't put this line between driver->beginScene(...) and driver->endScene() ???
(a little bit more code around this line would help, too) ;)
while(!asleep) sheep++;
IrrExtensions:Image
http://abusoft.g0dsoft.com
try Stendhal a MORPG written in Java
JP
Posts: 4526
Joined: Tue Sep 13, 2005 2:56 pm
Location: UK
Contact:

Post by JP »

and make sure you make that function call AFTER smgr->drawAll() as otherwise the scene will be drawn on top of the bar and hence it won't be visible!

you may be doing this already but i suggest you draw 2 boxes to represent your health bar. one which is 100% the size of the health bar and may be white in colour and another box on top of that which is the actual health value in size and green in colour so that the green health bar fills up the white box so you can see the percentage of health easily.
Image Image Image
Vintige
Posts: 11
Joined: Tue Nov 13, 2007 10:57 am

Post by Vintige »

Thankyou. Ive put the function after smgr->drawAll() and i can now see the health bar but it doesnt do nothing when i press A and S :x
rogerborg
Admin
Posts: 3590
Joined: Mon Oct 09, 2006 9:36 am
Location: Scotland - gonnae no slag aff mah Engleesh
Contact:

Post by rogerborg »

Vintige wrote:Thankyou. Ive put the function after smgr->drawAll() and i can now see the health bar but it doesnt do nothing when i press A and S :x
That sounds like a job for... DEBUGGER MAN. With the power to set breakpoints, examine variables, and follow execution, no bug can stand against his mighty powers of investigation!
Please upload candidate patches to the tracker.
Need help now? IRC to #irrlicht on irc.freenode.net
How To Ask Questions The Smart Way
Acki
Posts: 3496
Joined: Tue Jun 29, 2004 12:04 am
Location: Nobody's Place (Venlo NL)
Contact:

Post by Acki »

is node a valid pointer (!= 0) ???
did you pass the event receiver to the device ???
also remember the health is decreased only by 1 and only every time you release the key(s), so if you want it to get 0 you'll have to press the key 100 times !!! ;)
while(!asleep) sheep++;
IrrExtensions:Image
http://abusoft.g0dsoft.com
try Stendhal a MORPG written in Java
Post Reply