I have problem about draw2DImage to be 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
fon3m
Posts: 32
Joined: Thu Sep 28, 2006 9:34 pm

I have problem about draw2DImage to be health bar.

Post by fon3m »

I use draw2DImage to draw jpg file to be health bar. I use this code

Code: Select all

irrDevice->getVideoDrv()->draw2DImage(test1,::position2d<s32> (0,speed),core::rect<s32>(0,0,200,15), 0, video::SColor(255,255,255,255), true);
and When health bar decrease, it's draw new pic that shorter above the old health bar.
How to delete the old health bar?

Thank you
Acki
Posts: 3496
Joined: Tue Jun 29, 2004 12:04 am
Location: Nobody's Place (Venlo NL)
Contact:

Post by Acki »

You don't have to draw a new bar !!!
Just make the rect shorter (dependant on the health), that should do the trick... ;)
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 »

Yeah with this code it just draws the specified image every frame, for that frame only, it doesn't leave any image on screen after the frame has passed like an IGUIImage woulda, so as Acki says just decrease the size of the rectangle and it should show up smaller on the screen.
Image Image Image
fon3m
Posts: 32
Joined: Thu Sep 28, 2006 9:34 pm

Post by fon3m »

ummmm.......Please show me for sample. I don't understand.

thank you very much
raven_coda
Posts: 89
Joined: Thu Aug 17, 2006 8:11 pm
Location: Salt Lake City, UT, USA
Contact:

Post by raven_coda »

Here's code from my program on how I did something similar

Code: Select all

// setup
m_Energy = GUIEnv()->addImage(irr::core::rect< irr::s32 >(765,200,780,400));
	m_Energy->setImage(driver()->getTexture("bar.png"));
	

// in main loop
int hi=(int)(400-(pRacer.energyleft/pRacer.totalEnergy)*200);
	m_Energy->setRelativePosition(core::rect<s32>(765,hi,780,400));
  
Definition of an Upgrade: Take old bugs out, put new ones in.
fon3m
Posts: 32
Joined: Thu Sep 28, 2006 9:34 pm

Post by fon3m »

I will try it.

Thank you :P
fon3m
Posts: 32
Joined: Thu Sep 28, 2006 9:34 pm

Post by fon3m »

I try with this code

Code: Select all

void textS::drawText(getDevice* irrDevice,int p)
{  	
       text1 = irrDevice->getGUIEn()->addImage(irr::core::rect<irr::s32>(10,10,140,140));
       text1->setImage(irrDevice->getVideoDrv()->getTexture("media/artwork/t1.jpg"));
      
       if(pow==30)   // main set pow=30
       {
           text1->setRelativePosition(core::rect<s32>(10,10,100,100));
       }
}
and it's have 3 error are

Code: Select all

error C2440: '=' : cannot convert from 'class irr::gui::IGUIImage *' to 'class irr::gui::IGUIEnvironment *'
        Types pointed to are unrelated; conversion requires reinterpret_cast, C-style cast or function-style cast
error C2039: 'setImage' : is not a member of 'IGUIEnvironment'
        c:\program files\microsoft visual studio\vc98\include\iguienvironment.h(45) : see declaration of 'IGUIEnvironment'
 error C2039: 'setRelativePosition' : is not a member of 'IGUIEnvironment'
        c:\program files\microsoft visual studio\vc98\include\iguienvironment.h(45) : see declaration of 'IGUIEnvironment'
I don't know how to fix it. I look over in doc of irrlicht engine but i don't understand. Please help me and sorry about my stupid. :(
raven_coda
Posts: 89
Joined: Thu Aug 17, 2006 8:11 pm
Location: Salt Lake City, UT, USA
Contact:

Post by raven_coda »

is text1 declared as a IGUIImage* ? If not it should be.

Code: Select all


IGUIImage* text1=0;
Definition of an Upgrade: Take old bugs out, put new ones in.
fon3m
Posts: 32
Joined: Thu Sep 28, 2006 9:34 pm

Post by fon3m »

Oh! I can do it. Thank you. :D
Post Reply