Scripts / Here's one method to read in screen resolution [from file-optional] and centre sprites on screen

Author
Message
Bored of the Rings
GameGuru Master
19
Years of Service
User Offline
Joined: 25th Feb 2005
Location: Middle Earth
Posted: 15th Oct 2017 10:55 Edited at: 21st Oct 2017 08:11
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.....




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

Attachments

Login to view attachments
AmenMoses
GameGuru Master
8
Years of Service
User Offline
Joined: 20th Feb 2016
Location: Portsmouth, England
Posted: 15th Oct 2017 12:30
What's wrong with GetDeviceWidth & GetDeviceHeight?
Been there, done that, got all the T-Shirts!
PM
Bored of the Rings
GameGuru Master
19
Years of Service
User Offline
Joined: 25th Feb 2005
Location: Middle Earth
Posted: 21st Oct 2017 07:57 Edited at: 21st Oct 2017 08:10
ah yes absolutely nothing wrong using those 2 commands also. The code was to demonstrate how (if your a LUA / scripting beginner), how to load in values from a file (hence why I put optional in the title). It is more practical/efficient to use the GetDeviceWidth & GetDeviceHeight commands.
The focus was really to show how to center sprites on screen.

Anyway, I hope any beginners, or anyone who is not sure of how to use the LUA io commands, gets some benefit from the code.

Actually the code was originally a conversion of an old FPI script, but you can put the code that is in _main in the _init section and remove the condition i.e. "if state[e]==...." and the "end" statement after the line "state[e] = 10" (remove that too if you want). See lua code below:

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

Login to post a reply

Server time is: 2024-04-27 01:50:17
Your offset time is: 2024-04-27 01:50:17