[SOLVED] Problem centering text overlays (old System.ViewportWidth/Height)

Started by Nadarian, Wed 22/07/2020 11:16:20

Previous topic - Next topic

Nadarian

Hi there!

I followed the instructions from this 2008 video on youtube https://www.youtube.com/watch?v=79yTq3BQo14 to make my credits centered, but I guess one of these functions is outdated:

Code: ags

function  ShowTextCentered(String text) 
{
  int centerX, centerY;
  int textWidth, textHeight;
  int x, y;
  
  centerX = System.ViewportWidth / 2;
  centerY = System.ViewportHeight / 2;
  
  textWidth = GetTextWidth(text, eFontTumbleText);
  textHeight = GetTextHeight(text, eFontTumbleText, textWidth + 7);
  
  x = centerX - (textWidth / 2);
  y = centerY - (textHeight / 2);
  
  textOverlay = Overlay.CreateTextual(x, y, textWidth + 7, eFontTumbleText, 65535, text);
}


When trying to run it, the error " 'ViewportWidth' is not a public member of 'System' " shows up.
What should I write there instead? Or is there any better way to code this in the newest version?


Thanks in advance!
Teaching film photography in the 21st century.
Now, trying to do it through adventure games.

Crimson Wizard

You can use Screen.Width and Screen.Height respectively.

For similar cases try searching for the command in the manual (F1 in the editor), as it may tell if it's obsolete and which other command to use instead, e.g.:
https://github.com/adventuregamestudio/ags-manual/wiki/System#systemviewportwidth

I also recommend visiting topics in the manual called "Upgrade to AGS X.X.X", they tell what have changed.
For example: https://github.com/adventuregamestudio/ags-manual/wiki/UpgradeTo35#new-screen-struct


Nadarian

Thank you very much Crimson Wizard!

Actually looked for it in the manual as I already saw this "obsolete commands" thing many times before while searching there. Maybe I searched it wrong this time, because I couldn't find it.
I'll have this in mind, as some of the best tutorials in Youtube are a bit outdated.

Now my credits run smoothly.
Thanks!
Teaching film photography in the 21st century.
Now, trying to do it through adventure games.

Crimson Wizard

I believe we should add a big reference table for outdated commands to make things easier.

Nadarian

I tried to search it again in the manual, just to make sure.
And actually, if you search for "System.ViewportWidth" you get to the old page and it says very clearly: This property is obsolete since AGS 3.5.0. Use Screen.Width instead.

So.. my bad!! This reference table you mention could be great, but a proper use of the manual actually solves these problems.
Teaching film photography in the 21st century.
Now, trying to do it through adventure games.

Crimson Wizard

Quote from: Nadarian on Wed 22/07/2020 12:50:30
And actually, if you search for "System.ViewportWidth" you get to the old page and it says very clearly:

There's also a problem with the recent manual, in my opinion, after we changed how it's being generated member functions and properties are not mentioned in the Index, only full names (type.member) are. This is something I hoped to address too.

SMF spam blocked by CleanTalk