Jump to content
  • Advertisement
Sign in to follow this  

Scaling physics with screen resolution

This topic is 2358 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

I'm currently working on a 2D (vector based) game, and I of course want the players to be able to choose any resolution they wish. While I've successfully managed to scale the graphics properly, I can't seem to figure out how to scale the physics.
Take a look at this simple projectile code to get a better understanding of what I mean:
[source lang="vb"]bullet.gravity = 0.5
bullet.speed = 1

SUB projectilePhysics
IF bullet.stage = 1 THEN
bullet.x = turret.x2
bullet.y = turret.y2
bullet.xVel = COS(bullet.angle / 180 * Pi) * (bullet.power / bullet.speed)
bullet.yVel = SIN(bullet.angle / 180 * Pi) * (bullet.power / bullet.speed)
bullet.stage = 2
ELSEIF bullet.stage = 2 THEN
bullet.x = bullet.x + bullet.xVel
bullet.y = bullet.y + bullet.yVel
IF bullet.yVel < 12 THEN bullet.yVel = bullet.yVel + (bullet.gravity / (bullet.speed * bullet.speed))
END SUB[/source]
Let's say I'm running the game in 640x480, if [source lang="vb"]bullet.power = 20.5[/source] and [source lang="vb"]bullet.angle = 270[/source] (straight up), the 'bullet' will roughly reach a height of around 480 (well, technically 0, as 480 is the bottom, and 0 is the top). Now if I were to run the game in 800x600, the 'bullet' would of course, still only reach around 480, whereas I would want it to reach around 600 (and take the same amount of time to do so). I'm unsure as to what the math would be to achieve this. I've tried various ways, but nothing seems to give the desired affect.

Any help would be greatly appreaciated smile.png Edited by luke88

Share this post

Link to post
Share on other sites
Wouldn't a simple division by 480 and a multiplication by 600 do the trick? That is, divide by the height/width you designed for to get a value between 0 and 1 and then multiply by the height/width that you actually want. Don't do this in between calculations though, just when you're passing on positions to draw.

Share this post

Link to post
Share on other sites
Wow, that's so simple, thank you very much. I'm a bit annoyed at myself for not thinking of that. I've not tested it properly yet as my graphics scaling code works in a completely different, and ridiculous way, and I'm having to go back and change everything, but my preliminary tests suggests that it should all work fine :)
Thanks again Mussi. If I don't follow-up this post with new problems, it's safe to assume that it was all a success.

Share this post

Link to post
Share on other sites
Sign in to follow this  

  • Advertisement

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!