Thursday 5 April 2012

Virtual Resolution

AGK is very flexible when it comes to screen sizes and positions, it can work with practically any coordinate system you like.

It is this way because of it's cross-platform nature, it needs to be able to operate at the resolution of any of the devices it is run on.

It does this by having two sets of resolutions;
  • Physical - which for windows is defined in setup.agc and for phones and tables is defined by the hardware of the device screen.
  • Virtual - which is used to position objects on the screen 
This can be demonstrated by getting the values for both sets.

Add the following commands to the start of the project;

physWidth# = getDeviceWidth()
physHeight# = getDeviceHeight()
virtWidth# = getVirtualWidth()
virtHeight# = getVirtualHeight()

These simply get the values from the system and store them in four variables.  The # at the end of the names indicates the values will be floating point values (numbers with fractions), rather than integers (whole numbers).

The physical resolution can't possible have fractions of pixels, but storing the values as if they can will force the maths to use floating point which will make scaling more accurate.

Remove the setDisplayAspect() command and replace the loop block with the following;

do
printc( "Physical: " )
print( str( physWidth# ) + " x " + str( physHeight# ) )
printc( "Virtual: " )
print( str( virtWidth# ) + " x " + str( virtHeight# ) )
sync()
loop

The printc() command is like the print() command, except it doesn't perform a line feed at the end.  This allows multiple statements to print to one line.  In this case it makes the code more readable.

The str() command converts a value into a string to allow it to be joined to other strings (using the + ) for printing.

The complete project should now look like this;
Which should produce the following result.
To make it use the native resolution of the device, we use the setVirtualResolution() command, by adding the following at line 3;

setVirtualResolution( physWidth# , physHeight# )

Like this;
and now we get;
Which is much better.

No comments:

Post a Comment