GUI question or two

Mar 20, 2012 at 10:23 AM

I think I saw an example of this stuff in one of the more recent Ace videos, but the version of Ace in the repo is a bit older.

Much like in Ace, I've got a start screen set up with a title and a "Press Start" label attached to a screen. Now I'm trying to get some interesting stuff going on. I've gotten the Labels to move around the screen just fine, but when I wrote some code to animate the TextColor on my startLabel, it still comes up white. I'm not entirely sure what's going on. When I step through the Draw and check the game window, it's definitely changing colors, but running at full speed it stays white. Is something drawing the label again? I've set it up with a GameState containing a Layer which has a screen and both labels, which are added to the screen, and then I'm overriding the Layer's Draw() to change the label's TextColor property before base.Draw() gets called. Is this a correct way to be doing it? The IGF source seems to indicate it should be working.

Mar 20, 2012 at 10:32 AM

Aw, heck. Figures. Worked it out almost immediately after posting. Needed to do all it after base.Draw(), though I'm not entirely sure why.

Mar 20, 2012 at 5:39 PM

Try adding your TextColor change code in the Layer's overriden BeginDraw(...) method and make sure to call your Label.Invalidate() method right after changing a visual property.

IGF Gui system makes use of internal textures to draw only the stuff that needs to be drawn a bit like Windows work. However, some properties aren't invalidating the control (such as TextColor) and therefore you need to manually call it yourself.

Moreover, you should avoid modifying Gui properties during the Draw as you may confuse the whole rendering order system. Such properties should be modified during the Update method of a GameState or at least on the BeginDraw override of a Layer.

Mar 21, 2012 at 8:34 PM

Good to know. I'll make some modifications.

Though, as an aside, I looked at the Label code in IGF's source while I was trying to figure this out and the setter does call Invalidate()-- just in case anyone else needs to know this stuff.

Mar 21, 2012 at 8:47 PM

You're right, it definitivelly calls Invalidate() but it doesn't work because the dirty state is cleared after each draw. That's why modifications to the GUI controls should be made before the SunBurnLayer.Draw() method is called.

The SunBurnLayer.Draw() actually calls the SceneInterface.BeginFrameRendering() where all Controls states are verified and cleared.

Mar 21, 2012 at 9:37 PM

Makes sense. In any case, i was seeing a couple of odd little things happening intermittently. I've moved the stuff I was doing in Draw into an Update function that I'm calling from my GameState and it's cleaned the whole thing up nicely. that does explain why TextColor changes weren't working before the base.Draw() call but worked when placed after it, though.

I had a feeling something like that was happening. Regardless, I'm just going to keep this kind of stuff out of the Draw() chain.