How to put the 2D pic like HP on the screen of the camera?

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
ming
Posts: 11
Joined: Thu May 04, 2006 4:16 pm

How to put the 2D pic like HP on the screen of the camera?

Post by ming »

When I put the HP(Life) bar picture on the screen...is their any way that I can cut piece of it out...to make the HP Bar looks like it was decreased...or do I have to make another picture in photoshop and switch to it....Or in case of bullet..if I want to display many bullet pic on screen..do I have to duplicate them and put it side by side? and how can I take it off one by one...
sample...imagine that "I" is bullet....
first, before the gun was shot===> IIIIIIIIII
second,after it was shot 3 times==> IIIIIII
AndyCR
Posts: 110
Joined: Tue Nov 08, 2005 2:51 pm
Location: Colorado, USA
Contact:

Post by AndyCR »

Yes, look in the 2dgraphics example, driver->draw2dimage should be what you're looking for, you can choose a rect of an image to only draw part of it... I've used it in a menu system to draw multiple buttons from the same image.
area51
Posts: 338
Joined: Thu Mar 18, 2004 10:20 pm
Location: UK
Contact:

Post by area51 »

You can call this function each game loop:

Code: Select all

irr::video::ITexture* m_pAmmoBar;
...

//! Display horizontal ammo bar. Ammo as a percentage is shown
//! 100 max ammo, zero none. Ammo image 256 x 64 and represents
//! a row of 10 bullets
void CGamePlayState::displayAmmoBar(irr::s32 percent)
{
    irr::core::rect< irr::s32 > clip(20, 650, 20 + (256 * percent/100) , 650 + 64); 
	smgr->getDriver()->draw2DImage(m_pAmmoBar, irr::core::position2d< irr::s32 >(20,650), 
    irr::core::rect< irr::s32 >(0,0,256,128), 
    &clip, irr::video::SColor(255, 255, 255, 255), true); 
}


Pass in the current amount to be displayed as a percentage. (20 & 650 are screen x y co-ordinates where ammo bar is positioned, change these to defines or const int's or whatever)
________
Weed vaporizers
Post Reply