Problem with GUIButton and ITexture

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
odenter
Posts: 48
Joined: Thu Oct 21, 2004 10:35 am
Location: Bremen (Germany)

Problem with GUIButton and ITexture

Post by odenter »

I've one class for every GameState

Code: Select all

class GameState
{
  virtual void OnEnter();
  virtual void OnLeave();
  [...]
};

class GSIntro : public GameState
{
};

class GSPlay : public GameState
{
};
When game starts a GSIntro state is created, when state changes first an OnLeave method ist called, and then on the new state an OnEnter method.

Code: Select all

/**************************************************************************************************
* Name  :
*
* Desc  :
*
* Param :
*************************************************************************************************/
void GSIntro::OnEnter(irr::IrrlichtDevice *device, GameStateManager *gsMgr)
{
  this->deviceValue = device;
  this->gameStateManager = gsMgr;

  // Texturen für die Buttons laden
  this->newGameValue = this->deviceValue->getVideoDriver()->getTexture("images\\newGame.png");
  this->quitGameValue = this->deviceValue->getVideoDriver()->getTexture("images\\quit.png");

  this->deviceValue->getVideoDriver()->makeColorKeyTexture(this->newGameValue, 
                                                           irr::core::position2d<irr::s32>(0, 0));
  this->deviceValue->getVideoDriver()->makeColorKeyTexture(this->quitGameValue, 
                                                           irr::core::position2d<irr::s32>(0, 0));


  // gui erzeugen
  this->buttonNewGame = this->deviceValue->getGUIEnvironment()->addButton(irr::core::rect<irr::s32>(50,250,150,250 + 32), 
                                                    0, 
                                                    buttonID::NEWGAME, 
                                                    L"", 
                                                    L"Launches a new Window");
  this->buttonNewGame->setUseAlphaChannel(true);
  this->buttonQuitGame = this->deviceValue->getGUIEnvironment()->addButton(irr::core::rect<irr::s32>(50,300,150,300 + 32), 
                                                    0, 
                                                    buttonID::QUIT, 
                                                    L"", 
                                                    L"Quit Game");
  this->buttonQuitGame->setUseAlphaChannel(true);

  // den Buttons Texturen zuweisen
  this->buttonNewGame->setImage(this->newGameValue, 
    irr::core::rect<irr::s32>(0, 0, 100, 32));
  this->buttonQuitGame->setImage(this->quitGameValue, 
    irr::core::rect<irr::s32>(0, 0, 100, 32));

  this->backgroundValue = this->deviceValue->getVideoDriver()->getTexture("images\\backgroundGSIntro.jpg");
}
For the first time all works fine, but when I first change from GSIntro to GSPlay and then back to GSIntro in GSIntro the two buttons are rendered, but without my texture.
After GSIntro->OnEnter all objects(texture, button,...) are loaded correctly.
Everytime my state changes new objects are created.

So any adivice for me?

EDIT:
Here are two pictures of my problem.
http://88.198.14.185/~odenterdata/1.jpg
http://88.198.14.185/~odenterdata/2.jpg
Cristiano87
Posts: 13
Joined: Wed Oct 03, 2007 9:00 am
Location: Milano, Italia

Post by Cristiano87 »

maybe it happens because you don't destroy the previous buttons but...
a solution is to create only 2 objects and changing the textures between game states, because recreating (expecially if you don't destroy them) is memory expensive
another tip: try to don't load a texture if you loaded it before
Post Reply