making HUD, gui ADD IMAGE problem <--solved with easy way

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
Mutter
Posts: 11
Joined: Mon Jul 10, 2006 6:05 pm

making HUD, gui ADD IMAGE problem <--solved with easy way

Post by Mutter »

Hellooouuuuuuuuuuuu...thanks for irrlicht...realized things i couldn't dream of!

you all know the HUD in strategy games, do you?
ex.: Starcraft, Warcraft...
ok...i'm at a strategy game and thought...YEAH nice...
env->addimage(...) and had a nice grafical border
completely covering my screen and used alpha channel to have
all transparent where the real 3D game happens.

here's my PROBLEM:
--------------------------------------------------------------
HUD turned on visible causes strange problems in moving
on my playground...I use camera RAY of mouseposition and let this
collide with BoundingBoxes...i get mesh position with this collision
and move my playermodel 1 field further.
But my movement counter says i made 2 movement points.

HUD turned off, and everything is normal
... 1 field move = 1 movement point and NOT 2

i had bad problems with strange things bacause i didn't take
care of model IDs but now i set all right ...so i thought...hmmm
set my IGUIImage* ID to 0x0000...that means NO collision
testing with my ray....i also set ENABLED(0) of this GUIImage...
but same problem stays.
it seems my code for movement of my playermodel executes 2 times
when IGUIImage is visible


----------------------------------------------
----------------------------------------------
NEW:
i tested a bit and found out:
the GUIImage executed my "mouse button up" event
2 times i think which caused double calculations in movement
...dont know why...
the same problem accured with a GUIStaticText Box!!!
but with GUIButton s there was not the problem BUT only if i disabled them!!!...
so a gave up making a HUD with GUIIMAGE...


-------------------------------------------------------
HERE IS MY SOLVE (not really solved the GUI problem):

I looked for driver->draw2DImage(...);
problem was that i had to put this method into my while loop...
only then my draw2DImage showed up...but only behind
my 3D game objects!!!...NOT good for a HUD...
then i put draw2dimage right after smgr->DrawALL()
and before of gui->drawALL();

RESULT!!!!: my HUD draw2dimage shows in front of 3dgameobject
(no more behind) AND under the GUI elements like buttons...
TADAA...nice and easy HUD.
Last edited by Mutter on Tue Jul 11, 2006 11:42 pm, edited 2 times in total.
und wieder ein deutscher :)
vitek
Bug Slayer
Posts: 3919
Joined: Mon Jan 16, 2006 10:52 am
Location: Corvallis, OR

Post by vitek »

The collision testing done with the ICollisionManager only takes ISceneNode derived classes into account, so setting or changine the ID of the IGUIImages should not have an effect.

It sounds like your event receiver is not properly dealing with the click. You might want to post your event receiver code.

Just a note, but I believe drawing a single image over the whole screen with a large portion of it being totally transparent will cause a noticeable performance degredation. If possible, you might want to break your HUD up into multiple parts.
Mutter
Posts: 11
Joined: Mon Jul 10, 2006 6:05 pm

hmmm...jupp

Post by Mutter »

thanks for fast reply!

yeah ok...
SORRY didn't manage to make the code look nice here :(
if there is no other chance i must seperate my border into 4 :(
that would be ugly...
i have NO performance-- because of the transparent guiimage!!!
fps are with or without borders visible the same.



class MyEventReceiver : public IEventReceiver
{
public:
virtual bool OnEvent(SEvent event) // Create Keyboard Event
{
if(event.EventType == irr::EET_KEY_INPUT_EVENT)
{
// a change to the current state of the keyboard
keys[event.KeyInput.Key] = event.KeyInput.PressedDown;
// if not PressedDown, the key was lifted up
if (!event.KeyInput.PressedDown)
{
switch(event.KeyInput.Key)
{
case KEY_ESCAPE:
{
device->closeDevice();
break;
}
}
}
// we captured a keyboard event, so we return true
// return true;
}

if (event.EventType == EET_GUI_EVENT)
{
s32 id = event.GUIEvent.Caller->getID();

switch(event.GUIEvent.EventType)
{
case EGET_BUTTON_CLICKED:
{
if (id == 101) //button MOVE
{
player[activeplayer].SetMove(1);
dicebutton->setVisible(1);
movebutton->setEnabled(0);
movepoints->setVisible(0);

}
if (id == 102) //button DICE
{
player[activeplayer].SetMovepoints( (rand()%11) +2 );
movecursor->setVisible(1);
movecursor->setPosition(vector3df( charactermodel[ player[activeplayer].GetCharacterID() ]->getPosition() ) );

stringw str = player[activeplayer].Movepoints();
movepoints->setText(str.c_str());

dicebutton->setVisible(0);
movebutton->setEnabled(1);
movepoints->setVisible(1);

}

if (id == 106) //button SKIP
{
player[activeplayer].SetMovepoints( 0 );
movecursor->setVisible(1);


dicebutton->setVisible(0);
movebutton->setEnabled(1);
movepoints->setVisible(0);

if (activeplayer == 1)
{
activeplayer = -1;
}
activeplayer += 1;

activeplayertext->setText( charactermodel[player[activeplayer].GetCharacterID()]->getName() );
movecursor->setPosition(charactermodel[activeplayer]->getPosition());

}

break;
}
}
}



if(event.EventType == irr::EET_MOUSE_INPUT_EVENT)
{

switch(event.MouseInput.Event)
{
case irr::EMIE_LMOUSE_LEFT_UP:
{
SOME RAY collision CODE
break;
}


case irr::EMIE_MOUSE_MOVED:
{
SOME ray collsion CODE
}


}
}


}


// we didn't capture the event so we return false
return false;
}
};
und wieder ein deutscher :)
Post Reply