If you want to use your screen resolution to centre sprites right smack bang in the middle of your screen, you can do it this way by reading in your screen coords from a text file, although this is optional. Or you can simply set x,y screen coord variables. I haven't added any code yet to check if files exist before loading in sprites, text file etc. Will do that later.
in this example, I used the usual dynamic barrel entity to attach the script (you could load in the screen resolution text file from the global.lua if you wanted). Then, using the divehelmet HUD image file from FPSC, which is 512 x 64 in pixel size. Did some math to center the sprite and voila...
I personally, don't like working in percentages (even though I'm a statistical programmer ha)......but prefer working in pixels.....
state = {}
function getscreenres_init(e)
state[e] = 0
readin=0 ;
readfromfile = 1;
if readfromfile == 1 then
-- Opens a file in append mode
file = io.open("resolution.txt", "r");
-- sets the default input file as test.lua
io.input(file)
scrx=io.read()
scry=io.read()
readin = 1
io.close(file)
else
scrx=1600
scry=900
end
end
function getscreenres_main(e)
if state[e] == 0 then
myImage = LoadImage("gamecore\\thescarythinker\\helmets\\pickedupdive.tga",1)
imagewidth = GetImageWidth ( myImage ) -- get percentage width of image
imageheight = GetImageHeight ( myImage ) -- get percentage height of image
imgwpix = math.floor((imagewidth * scrx) / 100)
imghpix = math.floor((imageheight * scry) / 100)
imgcentx = (((scrx / 2) - (imgwpix / 2)) / scrx) * 100
imgcenty = (((scry / 2) - (imghpix / 2)) / scry) * 100
divepick = CreateSprite(myImage)
SetSpritePosition(divepick,imgcentx,imgcenty)
state[e] = 10 -- any value for now
end
PromptLocal (e,'scrx=' .. scrx .. ' scry=' .. scry .. ' imgw=' .. imagewidth .. ' imgh=' .. imageheight .. ' imgwpx=' .. imgwpix .. ' imghpx=' .. imghpix .. ' imgcentx=' .. imgcentx)
end
--optional
function getscreenres_exit(e)
end
Professional Programmer: Languages- SAS (Statistical Analysis Software) , C++, C#, VB, SQL, PL-SQL, JavaScript, HTML, Three.js, Darkbasic Pro (still love this language), Purebasic, others
Hardware: Dell Precision 490; AMD Radeon HD 7570; 12GB.
FPSC to GameGuru Tools: AutoWelder/SegAutoWelder, Entity+Weapon Welder, FPEtoBAT