SRB2 Message Board  

Go Back   SRB2 Message Board > Sonic Robo Blast 2 > Editing > Editing Help

Reply
 
Thread Tools Search this Thread
Old 06-20-2017   #1
Lach
Latch? Lock?? Lack???
 
Lach's Avatar
Default HUD rendering on different screen sizes

I'm trying to place an icon on the screen using Lua whenever a certain player variable is active. In green resolutions it works fine, but of course in non-green resolutions it strays from its intended placement due to the way SRB2 handles different aspects.

I subtracted values from v.width() and v.height() to try and circumvent the problem, but for some reason it renders off the screen in many resolutions, including green ones. I thought perhaps they were scaled values, so I divided by v.dupx() and v.dupy() respectively, which worked in green resolutions, but in others actually rendered the icon on the opposite side of the screen. If they don't return your screen size, what do v.width() and v.height() actually return? And how do I use v.dupx() and v.dupy()?
__________________
Check out my new SRB2 YouTube channel!
Cool mods I made:
Orb
Combine Ring Monitors
Lach is offline   Reply With Quote
Old 06-20-2017   #2
"Lat'"
AAAAAAAAAAAAAAAAAAA
 
"Lat'"'s Avatar
Default

If you just want to snap HUD items to the sides / top / bottom of your screen, V_SNAPTOLEFT, V_SNAPTORIGHT, V_SNAPTOBOTTOM and V_SNAPTOTOP should be of assistance, but these are pretty weird with how they handle stuff sometimes. (You won't ever be able to get something properly displaying accordingly to the SCORE/TIME/RINGS HUD in any resolution other than green)

v.width and v.height do return the actual screen size in pixels, meaning v.height in 1920x1080 will return 1080 (which is of course gonna be off the 320x200 base resolution SRB2 uses for HUDs).
That's where dupx and dupy basically become useful, these are scales used to draw HUD items properly depending on your resolution. You just have to divide v.width and v.height with the proper v.dup variable to get a screenheight/width value you can use for HUD drawing.
Code:
local screenwidth = v.width()/v.dupx()
local screenheight = v.height()/v.dupy()
If you drew a HUD at (screenwidth/2, screenheight-20), it would draw a HUD on the on the horizontal middle of the screen, and 20 units above the screen's bottom. But if you do that, avoid using SNAPTO flags since they will mess furhter with the display.

Hopefully my post made sense.
(Also anyone feel free to correct me if I fucked up completely in my explanation / got things wrong.)

TL;DR:
v.height() and v.width() return screen size in PIXELS
v.dupx() and v.dupy() are scales which are used to position the HUD items depending on the resolution. They have a different value for about each resolution. Dividing v.height by v.dupy and v.width by v.dupx returns values you can use to draw your HUD item properly without having to use SNAPTO flags.
__________________
Quote:
Originally Posted by Bronydude2k5 View Post
If you make me a Sash Lilac wad, I'll make you a sonic sprite hack of any choice.

Last edited by "Lat'"; 06-20-2017 at 08:49 AM.
"Lat'" is offline   Reply With Quote
Old 06-20-2017   #3
Monster Iestyn
Friendly Neighbour-Hood
Moderator
 
Monster Iestyn's Avatar
Default

Quote:
Originally Posted by "Lat'" View Post
(You won't ever be able to get something properly displaying accordingly to the SCORE/TIME/RINGS HUD in any resolution other than green)
...Ah, just checked the source code, and apparently the SCORE/TIME/RINGS part of the HUD use V_NOSCALESTART rather than the V_SNAPTO* flags. V_NOSCALESTART just means the starting position isn't scaled accordingly with the resolution but instead acts as if it were the default 320x200, which means it'll be closer to the top left corner in big resolutions.

This info may or may not be useful, I don't know really.
__________________
My page stuffed full of MIDI goodness!
The Hitchhiker's Guide to the Robo-Hoodiverse
Timeline of Sonic Robo Blast History!

That's an uppercase i, not a lowercase L, for the record.
Monster Iestyn is offline   Reply With Quote
Old 06-20-2017   #4
Lach
Latch? Lock?? Lack???
 
Lach's Avatar
Default

Quote:
Originally Posted by Lach View Post
I thought perhaps they were scaled values, so I divided by v.dupx() and v.dupy() respectively, which worked in green resolutions, but in others actually rendered the icon on the opposite side of the screen.
The issue I'm experiencing is that the screen width, height, and respective dup values are all yielding inconsistent results, even when divided. I can't seem to get any icon to appear the same number of pixels away from the right edge of the screen in all resolutions.
__________________
Check out my new SRB2 YouTube channel!
Cool mods I made:
Orb
Combine Ring Monitors
Lach is offline   Reply With Quote
Old 06-20-2017   #5
Monster Iestyn
Friendly Neighbour-Hood
Moderator
 
Monster Iestyn's Avatar
Default

V_NOSCALESTART may be just what you want then, Lach. When you set that flag the coordinates won't be scaled to a 320x200 base resolution, you can have to do that yourself if needed. Another thing that might help is that v.dupx() and v.dupy each have a second return value, which is just the first one in a fixed_t form. You can then multiply your 320x200 based coordinate or coordinates with them using FixedMul(y*FRACUNIT, fixeddupy) to get one that is scaled, or you can just do vid.width()-distance to get a location that's always distance pixels from the right edge or something.

Note that V_NOSCALESTART stops the V_SNAPTO* flags from working, not that you'd need them anyway.
__________________
My page stuffed full of MIDI goodness!
The Hitchhiker's Guide to the Robo-Hoodiverse
Timeline of Sonic Robo Blast History!

That's an uppercase i, not a lowercase L, for the record.

Last edited by Monster Iestyn; 06-20-2017 at 06:28 PM.
Monster Iestyn is offline   Reply With Quote
Reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT. The time now is 02:49 PM.


Powered by vBulletin® Version 3.8.7
Copyright ©2000 - 2017, vBulletin Solutions, Inc.