[SOLVED] Adding an image at the end of a "dynamic" label

Started by rongel, Wed 05/01/2022 16:36:27

Previous topic - Next topic

rongel

Hello!

I have a dynamic GUI label that shows various information, and the text and the text width will change during the gameplay. I would like to add a graphic symbol (a button) at the end of the label text. But because the text width varies, the symbol's X position should be adjusted as well. Otherwise there will be ugly overlapping or a too long gap. So how can I place the symbol directly at the end of the text?

I tried to use GetTextWidth command to count the characters from the label, but got nowhere. Is there a way to do this? Thanks!  :=
Dreams in the Witch House on Steam & GOG

Crimson Wizard

Quote from: rongel on Wed 05/01/2022 16:36:27
I tried to use GetTextWidth command to count the characters from the label, but got nowhere.

Why not? please tell what you did and what happened.

rongel

Actually, now that I tried it again, I got it working! I didn't know I was on the right track, so thanks CW for making me check it again!

I have now this in my repeatedly_execute:

Code: ags
int width = GetTextWidth(lblDate.Text, eFontfntTiny);
btnWeather.X = width +10;


Seems to be working perfectly.

Now that we are here, I'd like to ask that is this wise to have in rep exec? Does it consume memory / resources if the game is constantly checking and adjusting this?

Dreams in the Witch House on Steam & GOG

Cassiebsg

Answer this question: Do you really need it to be checked 40 time a sec?
Or can you do with just checking after you updated the label? I would put the code right after updating the label.  ;)
There are those who believe that life here began out there...

rongel

Quote from: Cassiebsg on Wed 05/01/2022 20:13:14
Answer this question: Do you really need it to be checked 40 time a sec?

Nope! I'll put it where my label is updated. Just curious to know what kind of impact things like these have on the gameplay.
Dreams in the Witch House on Steam & GOG

Crimson Wizard

#5
Quote from: rongel on Wed 05/01/2022 20:39:31Just curious to know what kind of impact things like these have on the gameplay.

Computers today are quite fast, and even if game runs at 60 fps there's a lot it may do in one frame without slowing down.
Recalculating text's width and changing button's position won't have any noticeable impact.
Still, my advice is to try not to do obviously wrong things, as bad habits persist, and excessive script work may once accumulate to something serious.

AGS does not have much diagnostic features builtin, but there's a "infinite FPS" mode that may be turned on. It will run the game updates as frequent as it can, and displaying fps counter on screen.
To turn "infinite fps" mode you need to run your game exe from command line as "game.exe --fps". Then during the game press Ctrl + E to toggle the mode. In simple games FPS may easily reach thousands.
This mode is useful to see the impact of some actions, as with very high fps numbers it will be easier to spot a relative difference. For example, a difference between 60 and 59 fps may not catch your attention, but if it drops from, say 1500 FPS to 500 in some room, that may be a reason to wonder what is happening.

rongel

Thanks for the answer CW, that super fps counter might come in handy!
Dreams in the Witch House on Steam & GOG

SMF spam blocked by CleanTalk