I've created a simple Pong game and I move the ball by adding a variable ballSpeed to its position in my update
game logic like:
void Update()
{
ballPosition += ballSpeed;
}
The problem is that the ballSpeed
is a D3DXVECTOR3
with componets: x = 10; y = 10; z = 0;
The thing is that when I increase the window's resolution from 640:480
to 1280:1024
the ball is moving slower because it takes more pixels to go.
And my question is: How can I make the ball move with the same speed regardless of the resolution of the monitor?
You can scale the speed by the ratio of the actual resolution to the development resolution. Since the gameplay in Pong is dominated by the horizontal motion, you can use the ratio of the widths:
ballSpeed = int(ballSpeed * width / 640.0);
You will probably want to do the same to the size of all the screen elements too, such as the ball.
This all assumes that you define "speed" as the time taken to cross the entire screen, not to cover a given number of inches. That calculation would depend on more than just the resolution.