Page 1 of 1

Need advices with scene switching

Posted: Tue Oct 28, 2008 2:28 pm
by Is3dpic
Hello,

In my game, I have to login first, then choose a server to pay on ( like a mmo).
Ok, I login and here is my problem : I have to delete the buttons, edits box, background image and then create the interface for server choosing, but what's the best here ? resetting device ? dropping it and creating another one ? or keeping it (which I really want to do) delete images , gui etc and draw new one but in this case I don't really know what to do..

I hope I'm clear, my keyboard bugs so forgive my spelling mistakes

thanks you

Re: Need advices with scene switching

Posted: Tue Oct 28, 2008 2:51 pm
by Acki
Is3dpic wrote:or keeping it (which I really want to do) delete images , gui etc and draw new one but in this case I don't really know what to do..
if you wantto do it this way then do it this way (I probably also would)... ;)
and the API is a realy magical place to gather informations:
http://irrlicht.sourceforge.net/docu/cl ... t.html#a31

Posted: Tue Oct 28, 2008 4:19 pm
by Is3dpic
Wow, that what I call a beautiful function lol, going to make tests..thanks.

Posted: Wed Oct 29, 2008 8:34 am
by Is3dpic
Ok after severals tests, I came up with only errors...I don't know how to use this.

Example :

Code: Select all

	IGUIElement*	elem2 = loginPasswordBox;
	elem2->remove();
I get an error on that, I don't know how to use it, can someone light me up ? thanks xD

Posted: Wed Oct 29, 2008 9:00 am
by JP
I suggest you learn how to program in C++ :P

What you've done there is created a garbage pointer and then tried to delete it, which is highly inadvisable and will almost always result in your app crashing.

You need to assign a valid pointer to elem2 before even thinking about dereferencing it.

Posted: Wed Oct 29, 2008 9:50 am
by Is3dpic

Code: Select all

IGUIElement* root = m_guienv->getRootGUIElement();
	root->getElementFromId(loginPasswordBox->getID(), false);
	root->remove();
Well, somehow I think I have almost it...tough this code doesn't delete the loginpasswordbox :P


Edit : Some progress so far ->

Code: Select all

	IGUIElement* root = m_guienv->getRootGUIElement();
	IGUIElement* e = root->getElementFromId(loginUsernameBox->getID(), true);
	if (e) e->remove(); 
It's does delete the button :P

Posted: Wed Oct 29, 2008 9:57 am
by JP
You should look at the docs to figure out how to use IGUIElement::getElementFromId properly ;)

It returns a pointer to the element that you asked for (could be NULL though if it couldn't find it)

So you should do this:

Code: Select all

IGUIElement* root = m_guienv->getRootGUIElement(); 
IGUIElement* myElement = root->getElementFromId(loginPasswordBox->getID(), false); 
if (myElement) myElement->remove();

Posted: Wed Oct 29, 2008 10:06 am
by Is3dpic
I found out this I just edited my post before you posted xP
thanks anyways for your help. <3

Posted: Wed Oct 29, 2008 10:33 am
by Is3dpic
It's not the end lol.
What does m_guienv->getRootGUIElement() really do ? Look my code :

Code: Select all

if (LogInButton->isPressed())
{
	IGUIElement* root = m_guienv->getRootGUIElement();
	IGUIElement* e= root->getElementFromId(loginPasswordBox->getID(), false);
	if (e)  e->remove();

}
It's delete the loginbutton and not the loginpasswordbox as expected and that I think because of getRootGUIElement() function...some lights plz thanks

Posted: Wed Oct 29, 2008 10:37 am
by Is3dpic
Ok :


Returns the root gui element.

This is the first gui element, parent of all other gui elements. You'll never need to use this method, unless you are creating your own gui elements, trying to add them to the gui elements without a parent.

and lol, LoginButton is first thing created so it's the parents, what Can I do now ? I want to delete the loginbutton and loginusernamebox, I think I'll have to mess with parents thingy, I'm digging api..

Posted: Wed Oct 29, 2008 11:28 am
by Acki
Is3dpic wrote:

Code: Select all

IGUIElement* e= root->getElementFromId(loginPasswordBox->getID(), false); 
huu, why you're getting the element by it's id if you already have the element, where you get the id to search for from ?!?!? :shock:
if you already have the pointers stored why not simply use them ??? ;)

Code: Select all

loginPasswordBox->remove();
loginbutton->remove();
loginusernamebox->remove();
or you can create one parent that holds all controls as childs so you just need to remove this single parent... ;)

Posted: Wed Oct 29, 2008 11:41 am
by JP
At least someone's awake, Acki!

Posted: Wed Oct 29, 2008 1:51 pm
by Is3dpic
Acki wrote:
Is3dpic wrote:

Code: Select all

IGUIElement* e= root->getElementFromId(loginPasswordBox->getID(), false); 
huu, why you're getting the element by it's id if you already have the element, where you get the id to search for from ?!?!? :shock:
if you already have the pointers stored why not simply use them ??? ;)

Code: Select all

loginPasswordBox->remove();
loginbutton->remove();
loginusernamebox->remove();
or you can create one parent that holds all controls as childs so you just need to remove this single parent... ;)
yes,

Code: Select all

loginPasswordBox->remove();
loginbutton->remove();
loginusernamebox->remove();
Yes, It's removes but It's make application crashing.

Also, I've tried :

Code: Select all

IGUIElement* parent;
and i've added all the buttons etc like that :
LogInButton = m_guienv->addButton( rect<s32>(330, 360, 430, 400), m_parent, -1, L"Log In" );
But I always end up with an error when I do m_parent->remove;

Posted: Wed Oct 29, 2008 2:11 pm
by Acki
Is3dpic wrote:Yes, It's removes but It's make application crashing.
how does it crash, what error message do you get ???

maybe you try to access them after removing ???
try to set the pointers to 0 after removing and always check if it's =! 0 before accessing them...

Code: Select all

loginPasswordBox->remove();
loginPasswordBox = 0;
loginbutton->remove();
loginbutton = 0;
loginusernamebox->remove();
loginusernamebox = 0;
and later:

Code: Select all

if(loginusernamebox) theName = loginusernamebox->getText();

Posted: Wed Oct 29, 2008 2:36 pm
by Is3dpic
Yeap, thats it ! thanks you vey munch, It's now working . :P