Adventure Game Studio

AGS Support => Beginners' Technical Questions => Topic started by: Monsieur OUXX on Sun 29/12/2019 20:10:44

Title: Quick Viewport helpers for upgrading from 3.4.x to 3.5 or higher
Post by: Monsieur OUXX on Sun 29/12/2019 20:10:44
Add a module to your game and paste this script into it.
Your game created in 3.4.x should compile in 3.5.x without complaining about the new Viewports system. Please note that you'll have to "replace all" System.ViewportHeight and System.ViewportWidth with System.ViewportHeight() and System.ViewportWidth().

Please note that I did that in exactly 5 minutes and it seemed to work with Tumbleweed (calin leafshade wink wink) but I didn't test thoroughly.
Also, if someone already posted that before then please ignore and assume that their version is better.



Code for the module's header:
Code (ags) Select

import int ViewportHeight(static System);
import int ViewportWidth(static System);
import int ScreenHeight(static System);
import int ScreenWidth(static System);
import int GetViewportX();
import int GetViewportY();
import void SetViewport(int x,  int y);
import void ReleaseViewport();




Code for the module's body:
Code (ags) Select

int ViewportHeight(static System)
{
  return Game.Camera.Height;
}

int ViewportWidth(static System)
{
  return Game.Camera.Width;
}


int ScreenHeight(static System)
{
  return Game.Camera.Height;
}

int ScreenWidth(static System)
{
  return Game.Camera.Width;
}

int GetViewportX()
{
  return Game.Camera.X;
}

int GetViewportY()
{
  return Game.Camera.Y;
}

void SetViewport(int x,  int y)
{
  Game.Camera.SetAt(x,  y);
}

void ReleaseViewport()
{
  Game.Camera.AutoTracking = true;
}



Title: Re: Quick Viewport helpers for upgrading from 3.4.x to 3.5 or higher
Post by: Crimson Wizard on Sun 29/12/2019 22:19:51
There's also a "Script compatibility level" option in General Settings that will return all the old functions back if you set it to previous version.