Sorry your browser is not supported!

You are using an outdated browser that does not support modern web technologies, in order to use this site please update to a new browser.

Browsers supported include Chrome, FireFox, Safari, Opera, Internet Explorer 10+ or Microsoft Edge.

Newcomers DBPro Corner / Multi Resolution Text and Sprite Positioning

Author
Message
Smokie
13
Years of Service
User Offline
Joined: 14th Apr 2011
Location: Manchester. UK
Posted: 14th Apr 2011 21:29
How do I ensure that no matter what screen resolution I use, that Text and Sprites/Images are positioned in the same place.

I almost get my head around what needs to be done in theory,

ie: working out scale/ratio constants etc., but when it comes down to the practice of putting it inside a function that I can call, my head explodes.

ie
Display_PlayerDat(10,10,16,"Name)
Display_Sprite(100,100,10)

Function PlayerDat(xpos,ypos,txt_size$,data$)
xpos=? maths to work out resolution dependant value
xpos=? maths to work out resolution dependant value
txt_size=? proportional text height
etc
endfunction

sprite function i would imagine would be very similar once scaling factor was worked out...just a matter of scale sprite, and position same as text etc

I would call myself an intermediate coder and can usually figure out much harder things than this, but pls just a pointer in the right direction would be very much appreciated, I dont necessarily need code, just some guidance/advice!
Agent
20
Years of Service
User Offline
Joined: 7th Sep 2004
Location: Sydney, Australia
Posted: 15th Apr 2011 03:14 Edited at: 15th Apr 2011 03:17
There are several ways to do this, but since you mentioned 'scaling' in your thoughts I can point you in one direction.

Are you aware of the SCREEN WIDTH() and SCREEN HEIGHT() functions? In combination they return the current screen resolution, so that the code can determine what res it's running in. You can apply a multiplier to all your screen coordinates by calculating the multiplier as a ratio of some arbitrary source resolution (such as the resolution you were using when you built the code).

If you are building in 640*480, for example, and the program detects that it is running in 1280x960, your multiplier would be 2, and you'll multiply all screen coordinates by this value so that you keep objects in the same relative position on the screen.

You can calculate the multiplier dynamically by devising an appropriate formula that determines the ratio of the return values from SCREEN WIDTH() and SCREEN HEIGHT() to the resolution you are building in.

CONSTANT xmult# = SCREEN WIDTH() / buildresx
CONSTANT ymult# = SCREEN HEIGHT() / buildresy

Now multiply all screen coordinates and sprite scales that appear in your code by these multipliers.

Smokie
13
Years of Service
User Offline
Joined: 14th Apr 2011
Location: Manchester. UK
Posted: 16th Apr 2011 00:51
Thanks Agent

Covers everything I wanted to know, pretty much how I thought but you managed to explain it in a way can fathom.

Your the best

Login to post a reply

Server time is: 2024-11-24 04:58:17
Your offset time is: 2024-11-24 04:58:17