Original Post
Hello all! I am trying to build a simple 2D side scrolling game using C# and the (semi) new Microsoft XNA framework, but have run into a problem. Firstly, I have an image on the screen that I want to "jump." When it jumps, I assign an upward acceleration for the instant, and then in the next frame, I assign no upward acceleration, but just let gravity kick in, and he correctly begins to go upward more slowly, and then downward toward the earth. For the most part, the framerate is constant, so everything is smooth. When the framerate is not constant, however, I experience a problem. Across the board, I multiply all "time oriented values" (acceleration, velocity) by the amount of time it took to display this frame, so that framerate is not an issue. For example, if a sprite is moving to the right at 4pixels/frame and it takes 3 frames to display, the game will auto-correct itself and go 12 pixels. If it takes 1 frame of time, it will only move 4. I understand this to be a common approach. This system breaks down when I assign the instantaneous acceleration to the "jump", however. Since multiplying by time will not give the correct predictive result (the system doesn't know that the acceleration should stop for the next frame..how could it?). So what ends up happening is that if the game lags right when I am jumping, my character jumps too high (it assumes I want to apply that acceleration for multiple frames). Is there anything I can do about this? Thanks!