Page 1 of 1

Setting the text on staticText

Posted: Wed Dec 17, 2008 17:02
by liamrudel
Hi I'm new to CEGUI and want to use some static text to display a score. Can I reset the text after I first set it?

Code: Select all

/ setup GUI system
   mGUIRenderer = new CEGUI::OgreCEGUIRenderer(mWindow,
    Ogre::RENDER_QUEUE_OVERLAY, false, 3000, mSceneMgr);
   mGUISystem = new CEGUI::System(mGUIRenderer);
   CEGUI::Logger::getSingleton().setLoggingLevel(CEGUI::Informative);
   // load scheme and set up defaults
   CEGUI::SchemeManager::getSingleton().loadScheme(
    (CEGUI::utf8*)"TaharezLookSkin.scheme");
   mGUISystem->setDefaultMouseCursor(
    (CEGUI::utf8*)"TaharezLook", (CEGUI::utf8*)"MouseArrow");
   mGUISystem->setDefaultFont((CEGUI::utf8*)"BlueHighway-12");
   CEGUI::MouseCursor::getSingleton().setImage("TaharezLook", "MouseArrow");
   CEGUI::MouseCursor::getSingleton().show( );

   win = CEGUI::WindowManager::getSingletonPtr();
    sheet = win->createWindow("DefaultGUISheet", "CEGUIDemo/Sheet");

   score = win->createWindow("TaharezLook/StaticText", "CEGUIDemo/ScoreText");
   score->setText("Score: ");
   score->setSize(CEGUI::UVector2(CEGUI::UDim(0.15, 0), CEGUI::UDim(0.05, 0)));
   score->setPosition(CEGUI::UVector2(CEGUI::UDim(0, 0), CEGUI::UDim(0.85, 0)));
   sheet->addChildWindow(score);

   lives = win->createWindow("TaharezLook/StaticText", "CEGUIDemo/LivesText");
   lives->setText("Lives: ");
   lives->setSize(CEGUI::UVector2(CEGUI::UDim(0.15, 0), CEGUI::UDim(0.05, 0)));
   lives->setPosition(CEGUI::UVector2(CEGUI::UDim(0.85, 0), CEGUI::UDim(0.85, 0)));
   sheet->addChildWindow(lives);

    mGUISystem->setGUISheet(sheet);

I do that in a setup function and then in frameStarted I want to change the text but it comes up with a memory access violation when I:

Code: Select all

lives->setText("Lives: " StringConverter::toString(numLives));


How can I change the text every frame?

Posted: Wed Dec 17, 2008 18:10
by Kevin
Hello,

Well, for one thing, that is not how you combine (that is, concatenate) strings.

You probably want something like this:

Code: Select all

lives->setText("Lives: " + StringConverter::toString(numLives));


Hope that helps!

Kevin

Posted: Wed Dec 17, 2008 18:27
by Pompei2
Else than that, the code looks ok at a first glance, but did you take a look at the logfile ?

Posted: Wed Dec 17, 2008 21:20
by liamrudel
Weird it's working now, not sure what I changed might have been the + stringConverter but it was wrong in the post because I wrote it from memory. Anyway thanks for the speedy replies.

Liam

Posted: Thu Dec 18, 2008 09:05
by scriptkid
On a sidenote, to avoid a possible performance hit you might want to update your text label(s) only when the content has actually changed, instead of a few hundred times per second.

So i would suggest something like:

Code: Select all

if (oldNumLives != numLives)
{
  lives->setText("Lives: " + StringConverter::toString(numLives));
  oldNumLives = numLives;
}


Just a heads-up :)