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 / Same sprite size and position no matter what resolution

Author
Message
Chibi Babble
21
Years of Service
User Offline
Joined: 1st Feb 2003
Location:
Posted: 30th Jul 2008 20:19
I have a 3d game that I'm trying to use sprite icons for.

When the resolution is greater, obviously the sprite appears smaller due to the number of pixels, etc.

I'm racking my brain and trying to figure out what the best route to go with to make sure, to the player, the sprite looks exactly the same size and is in the same place. Like a HUD.

Any ideas?

Chibi?
Destrugter 1
18
Years of Service
User Offline
Joined: 26th Oct 2006
Location:
Posted: 30th Jul 2008 20:23
Set the window size to 640x480 =P

Or alternitively, you could use "Screen Width" and "Screen Height" and do some multiplications and divisions.
Chibi Babble
21
Years of Service
User Offline
Joined: 1st Feb 2003
Location:
Posted: 30th Jul 2008 20:30
Thats actually what I'm trying to figure out, the math

Chibi?
Destrugter 1
18
Years of Service
User Offline
Joined: 26th Oct 2006
Location:
Posted: 30th Jul 2008 20:43
Figure out what percent the sprite is on the resolution you made.
I'll show you an example.

Let's say you made the sprite at 640x480. Say he is 50x50. The percent of the screen it takes up is. It takes up 7.1825% of the x-axis pixels and 10.4167% of the y-axis pixels. So what you would do is store these in a float as let's say....
Sprite_X# = 0.071825
Sprite_Y# = 0.104167

Then store the screen resolution in variables.
Screen_X = Screen Width
Screen_Y = Screen Height

Then do some dividing. It will look like:
Sprite_Size_X = ceil(Screen_X / Sprite_X#)
Sprite_Size_Y = ceil(Screen_Y / Sprite_Y#)

Then, set your sprite size to that like:
Size Sprite 1,Sprite_Size_X,Sprite_Size_Y

Sry if you don't use underscores, I do but that should give you the idea.
Chibi Babble
21
Years of Service
User Offline
Joined: 1st Feb 2003
Location:
Posted: 30th Jul 2008 20:52
Trying this now.

Thanks for the super fast help. This forum really is the best.

Chibi?
Destrugter 1
18
Years of Service
User Offline
Joined: 26th Oct 2006
Location:
Posted: 30th Jul 2008 21:01
Lol np...really hope it works, please tell me if it does.
Phaelax
DBPro Master
21
Years of Service
User Offline
Joined: 16th Apr 2003
Location: Metropia
Posted: 30th Jul 2008 21:06
If I ran a video game at 1600x1200 and the HUD took up just as much room as it did at 640x480 I probably wouldn't play the game.


Chibi Babble
21
Years of Service
User Offline
Joined: 1st Feb 2003
Location:
Posted: 30th Jul 2008 21:06
Quote: "Sprite_Size_X = ceil(Screen_X / Sprite_X#)
Sprite_Size_Y = ceil(Screen_Y / Sprite_Y#)"


wouldn't this actually make the sprite HUGE?

If we plug everything in:
sprite_size_x = ceil(640/0.071825) --> 8911

Chibi?
Destrugter 1
18
Years of Service
User Offline
Joined: 26th Oct 2006
Location:
Posted: 30th Jul 2008 21:09
Whoops...just substitute the "/" with "*" I meant multiply =P, Sry about that.
Chibi Babble
21
Years of Service
User Offline
Joined: 1st Feb 2003
Location:
Posted: 30th Jul 2008 21:09
Quote: "If I ran a video game at 1600x1200 and the HUD took up just as much room as it did at 640x480 I probably wouldn't play the game.
"


The game is more arcade-like. So it isn't a HUD exactly. Basically its to show your score.

Chibi?
Chibi Babble
21
Years of Service
User Offline
Joined: 1st Feb 2003
Location:
Posted: 30th Jul 2008 21:14
Quote: "Whoops...just substitute the "/" with "*" I meant multiply =P, Sry about that. "


You're code may work for positioning the sprite but it won't for the size as that method is always going to make it equal back to the original size


The reason is:

x/y=z

y=x*z

That last bit of code is just finding out y which we already know to be the sprite width.

I think we're going the right direction though

Chibi?
Destrugter 1
18
Years of Service
User Offline
Joined: 26th Oct 2006
Location:
Posted: 30th Jul 2008 21:20
That would work for the sprite size...cause throw it into 1024x768.

The amount of x pixels turns into 73.5488, the y is 80.0003.

Remember in the example that was for a 50x50 sprite at 640x480...so the x and y pixels are definitely changing, only use those percentages if you are using a 50x50 sprite on a 640x480 resolution. If you are using a 32x32 sprite at 640x480, then you have to divide the x pixels by 640, then the y pixels by 480.

Find the resolution you are running on first, then we can move on from there.
Chibi Babble
21
Years of Service
User Offline
Joined: 1st Feb 2003
Location:
Posted: 30th Jul 2008 21:27
I think what your talking about is something like:



Sprite_Size_X = ceil((sprite_width/640)*Screen Width())


Right?

That way it finds out how much room it would take up on a 640x480 screen and blows it up that same percentage on a larger resolution.

Chibi?
Destrugter 1
18
Years of Service
User Offline
Joined: 26th Oct 2006
Location:
Posted: 30th Jul 2008 21:31
That is exactly what I was saying...it either enlarges or shrinks the sprite...but use the resolution you made the sprite on...if you made it on 1600x1200 and you use that then everything would be thrown off and it would look tons smaller then it is.
Chibi Babble
21
Years of Service
User Offline
Joined: 1st Feb 2003
Location:
Posted: 30th Jul 2008 21:32
Thanks!

Chibi?
HowDo
21
Years of Service
User Offline
Joined: 28th Nov 2002
Location: United Kingdom
Posted: 30th Jul 2008 22:05
Not sure what the scale difference is between screens, would the sprite scale command be an easier way of doing it.

Dark Physics makes any hot drink go cold.
Chibi Babble
21
Years of Service
User Offline
Joined: 1st Feb 2003
Location:
Posted: 30th Jul 2008 22:08
Destrugter 1 suggestion works the best for all the calculations.

However now I need to figure out x and y positioning.

Chibi?
Destrugter 1
18
Years of Service
User Offline
Joined: 26th Oct 2006
Location:
Posted: 31st Jul 2008 00:16
Just simply do that too all of your sprites...and see how many you can fit in the screen and that will give you how many objects you can do that with...so basically say your sprites are all 50x50 on a 640x480 screen...you can fit 12.8 sprites across, and 9.6 down...so basically that formula could do that, you just have to check and see if any are overlapping.
Chibi Babble
21
Years of Service
User Offline
Joined: 1st Feb 2003
Location:
Posted: 31st Jul 2008 01:52
Thanks! I'm all set now!

Chibi?
Destrugter 1
18
Years of Service
User Offline
Joined: 26th Oct 2006
Location:
Posted: 31st Jul 2008 02:30
Sweet, np.

Login to post a reply

Server time is: 2024-11-24 22:51:40
Your offset time is: 2024-11-24 22:51:40