User Interface help [Solved]

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
MaloW
Posts: 5
Joined: Fri Feb 12, 2010 6:01 pm

User Interface help [Solved]

Post by MaloW »

Hey guys, I'm quite a beginner so go easy on me if this information is easily obtained through some guide here or something.

I'm having a hard time understanding how the GUI works in Irrlicht. So far I've learned how to add an Image and how to write a static text. Problem is I don't know how to remove/edit the image/text and I dont know how to write out variable values in text.

As you can see in the screenshot below, the top-left image should be there at all times. But the one below it should dissappear when you press 1-4 and the tower get built (I've allready managed to make it appear only after pressing B). I also want to be able to write out all the data you can see at the very top in the windows-frame in the black boxes of the GUI.

Screenshot:

Image

Current code:

Code: Select all

gui::IGUIEnvironment* env = device->getGUIEnvironment();
	device->getGUIEnvironment()->addImage(device->getVideoDriver()->getTexture("media/ui1.jpg"),
		core::position2d<s32>(5,5));

Which would be the easiest/best way to do this? I would like to be able to change the size of the text and maybe even the font of it, but that's not a requirement :P
Last edited by MaloW on Sat Feb 13, 2010 2:40 pm, edited 1 time in total.
Mux
Posts: 56
Joined: Mon Feb 26, 2007 12:25 pm
Location: Stockholm

Post by Mux »

Some answers:
To remove your image you should first create it so that you can operate on it, like this:

Code: Select all

gui::IGUIImage *img;
img=device->getGUIEnvironment()->addImage(device->getVideoDriver()->getTexture("media/ui1.jpg"), 
      core::position2d<s32>(5,5));
Then when you want to get rid of it you simply write:

Code: Select all

img->remove();
You can do the same thing with the static text.
If I where you I would first create a "createTowerGUI-method" that draws your tower building menu and then create a "rmoveTowerGUI-metod" that would remove all components associated with the that gui.

To write out variable values you have to do something like this:

Code: Select all

core::stringw Temp=""; 
Temp+=p.getScore();
const wchar_t *ScorePointer=Temp.c_str(); 
score_text->setText(ScorePointer);
This is from one of my projects and handels the score display; I create an empty temp sting add my current score to it (an int), convert it to const wchar_t and then I set the static text score_text to display my ScorePointer.
It'll only take a minute or two to debug this code...
MaloW
Posts: 5
Joined: Fri Feb 12, 2010 6:01 pm

Post by MaloW »

Thx for your answers.

The img->remove(); part doesnt really seem to work for me though. Nothing happends, the .jpg image stays visable.

The text part worked excellent, now I don't get converting errors from int to wchar anymore. Allthough I'm having the same problem here now aswell, text->remove(); doesnt seem to work for text either. So my values of the varibles just keep writing on top of the old ones, which ends in a very cluttered area with alot of numbers written on top of each other.
Mux
Posts: 56
Joined: Mon Feb 26, 2007 12:25 pm
Location: Stockholm

Post by Mux »

That is strange. Are you using Irrlicht 1.7? I wrote a quick demo to test it and I got it to work fine.
It'll only take a minute or two to debug this code...
MaloW
Posts: 5
Joined: Fri Feb 12, 2010 6:01 pm

Post by MaloW »

Ah, I've forgotten to update Irrlicht :) I was still using 1.5.
After updating to 1.7 I'm getting some errors though:

Image

I'm using DevC++ 4.9.9.2, and I used the same guide for setting it up that I used for Irrlicht 1.5 (http://irrlicht.sourceforge.net/tut_devcpp.html).

Did I do anything wrong setting it up or is it because of the new Irrlicht version that I'm getting these errors? Since I don't really understand them help would be appreciated :)
Mux
Posts: 56
Joined: Mon Feb 26, 2007 12:25 pm
Location: Stockholm

Post by Mux »

Judging from the error messages it's because of the new Irrlicht version. You have to take a look in the API to see how you should call the newer version of the getCollisionpoint-method.
It'll only take a minute or two to debug this code...
MaloW
Posts: 5
Joined: Fri Feb 12, 2010 6:01 pm

Post by MaloW »

I looked up getCollisionpoint in the API section:

Code: Select all

virtual bool irr::scene::ISceneCollisionManager::getCollisionPoint  	(  	
		const core::line3d< f32 > &   	 ray,
		ITriangleSelector *  	selector,
		core::vector3df &  	outCollisionPoint,
		core::triangle3df &  	outTriangle,
		const ISceneNode *&  	outNode	 
	) 	
Seems like it's the outNode part that's new. Can't get it to work though.

My code:

Code: Select all

		    core::line3d<f32> line;
		    line.start = camera->getPosition();
		    line.end = line.start + (camera->getTarget() - line.start).normalize() * 2000.0f;
		    core::vector3df intersection;
		    core::triangle3df tri;
		    scene::ITriangleSelector* towerselector;
		    scene::ISceneNode* tempnode;

if (smgr->getSceneCollisionManager()->getCollisionPoint(
		    	       line, towerselector, intersection, tri, tempnode))
Error:

Code: Select all

no matching function for call to `irr::scene::ISceneCollisionManager::getCollisionPoint(irr::core::line3d<irr::f32>&, irr::scene::ITriangleSelector*&, irr::core::vector3df&, irr::core::triangle3df&, irr::scene::ISceneNode*&)' 

note: candidates are: virtual bool irr::scene::ISceneCollisionManager::getCollisionPoint(const irr::core::line3d<irr::f32>&, irr::scene::ITriangleSelector*, irr::core::vector3df&, irr::core::triangle3df&, const irr::scene::ISceneNode*&) 
Mux
Posts: 56
Joined: Mon Feb 26, 2007 12:25 pm
Location: Stockholm

Post by Mux »

Thats strange, the only thing I can se that differs from the code in the Irrlicht demo is that

Code: Select all

scene::ISceneNode* tempnode;
should be

Code: Select all

const scene::ISceneNode* tempnode;
It'll only take a minute or two to debug this code...
MaloW
Posts: 5
Joined: Fri Feb 12, 2010 6:01 pm

Post by MaloW »

That did it :) Thx for the help, still getting alot of warnings about OctTree, but as long as it compiles I'm good :)

img->remove(); works now!

Thx for all your help.
hybrid
Admin
Posts: 14143
Joined: Wed Apr 19, 2006 9:20 pm
Location: Oldenburg(Oldb), Germany
Contact:

Post by hybrid »

Just rename them to Octree (only 1 't').
Post Reply