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 AppGameKit Corner / Sprite coordinates based on virtual resolution

Author
Message
Captain Ouais
20
Years of Service
User Offline
Joined: 12th Dec 2003
Location: France
Posted: 18th Jul 2017 20:49
Hello the coders !!

I start a new game.
I create the charts in 1080/1812
I place, therefore, all my sprites according to the vitual resolution 1080/1812.
Obviously, not all smartphones have this resolution. So I create a little routine to fit the background image and resolution according to each screen (SetVirtualResolution( x# , y# ))
How do you make the sprites positioned according to the virtual resolution?
For example, if in 1080/1812 I position a sprite in 300/300 how to make it keep its position on the screen if I reduce the virtual resolution?

I tried calculating like this:

x1=(1080*300)/(GetVirtualWidth())
y1=(1812*300)/(GetVirtualHeight())

But the sprite does not remain on the spot and descends diagonally

Help




I do what i do !!!
bszaronos
7
Years of Service
User Offline
Joined: 7th Jul 2017
Location:
Posted: 18th Jul 2017 22:21
What I would do... The problem is that the getvirtual sizes are going to change based on screen sizes, so you are going to have to set variables based on this change.

You will need to do something like


The numbers I used are not the right numbers, you will have to test on different screens. and I just used the virtualwidth variable, you could use both if you want.
Coilwinder
11
Years of Service
User Offline
Joined: 28th Feb 2013
Location: Norway
Posted: 19th Jul 2017 00:05
I'm not sure I quite get the problem (on the other hand this sort of things can give me a headache Also, isn't this exactly what the SetVirtualResolution stuff is for?), but:

Quote: "For example, if in 1080/1812 I position a sprite in 300/300 how to make it keep its position on the screen if I reduce the virtual resolution?

I tried calculating like this:

x1=(1080*300)/(GetVirtualWidth())
y1=(1812*300)/(GetVirtualHeight())
"


Shouldn't that be:
x1=(GetVirtualWidth()*300)/1080
y1=(GetVirtualHeight()*300)/1812
?

But instead of that, isn't all you need simply a "SetVirtualResolution( 1080, 1812 )" ? Or am I missing something?
Apologies for any typos and strange grammar.
Captain Ouais
20
Years of Service
User Offline
Joined: 12th Dec 2003
Location: France
Posted: 19th Jul 2017 19:22
Thank you bszaronos, I try to make a routine for all resolutions!

Thank you, coilwinder i give you a "A" in mathematics and D----- for me !!!!

1000 thanks !

X1 and y1 are the position of a sprite according to the ration of the resolution! Cool eh!


I do what i do !!!

Login to post a reply

Server time is: 2024-11-22 15:40:06
Your offset time is: 2024-11-22 15:40:06