Setting the text on staticText

For help with general CEGUI usage:
- Questions about the usage of CEGUI and its features, if not explained in the documentation.
- Problems with the CMAKE configuration or problems occuring during the build process/compilation.
- Errors or unexpected behaviour.

Moderators: CEGUI MVP, CEGUI Team

liamrudel
Just popping in
Just popping in
Posts: 4
Joined: Wed Dec 17, 2008 16:52

Setting the text on staticText

Postby liamrudel » Wed Dec 17, 2008 17:02

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?

User avatar
Kevin
Not too shy to talk
Not too shy to talk
Posts: 29
Joined: Mon May 26, 2008 15:44

Postby Kevin » Wed Dec 17, 2008 18:10

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

Pompei2
Home away from home
Home away from home
Posts: 489
Joined: Tue May 23, 2006 16:31

Postby Pompei2 » Wed Dec 17, 2008 18:27

Else than that, the code looks ok at a first glance, but did you take a look at the logfile ?

liamrudel
Just popping in
Just popping in
Posts: 4
Joined: Wed Dec 17, 2008 16:52

Postby liamrudel » Wed Dec 17, 2008 21:20

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

User avatar
scriptkid
Home away from home
Home away from home
Posts: 1178
Joined: Wed Jan 12, 2005 12:06
Location: The Hague, The Netherlands
Contact:

Postby scriptkid » Thu Dec 18, 2008 09:05

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 :)
Check out my released snake game using Cegui!


Return to “Help”

Who is online

Users browsing this forum: No registered users and 8 guests