TGC Codebase Backup



Simple way to keep scale of your GUI regardless of resolution by TFE

22nd Nov 2010 20:32
Summary

A function to make your game interface look exactly the same in all resolutions.



Description

This set of two functions work as multipliers for any coordinates in your program.

By simply dividing your current x/y resolution with the base x/y resolution you choose, you get the multiplier you should use.
e.g. (as in the code) 1680/1024 = Multiplier which is approx 1.64

then simply multiply all your x coordinates with the xMulti and the y coordinates with the yMulti

If the current resolution is higher than the base, all coordinates will be scaled up to compensate for the smaller pixels and vise versa.



Code
                                    ` This code was downloaded from The Game Creators
                                    ` It is reproduced here with full permission
                                    ` http://www.thegamecreators.com
                                    
                                    ``Use function

width = 1680
height = 1050
set display mode width, height, 32, 1 ``set any display mode you want

basewidth = 1024 ``this is the mode for which you GUI was designed
baseheight = 768

xMultiplier(1280,basewidth)
yMultiplier(1050,baseheight)

do
box 50 * xMulti, 50 * yMulti, 500 * xMulti, 500 * yMulti

rem this box will have the exact same size in any resolution

wait key
end

``Declare functions

function xMultiplier(x,basex) 
   xMulti = x / basex
endfunction xMulti

function yMultiplier(y,basey) 
   yMulti = y / basey
endfunction yMulti