Benjamin Deutsch wrote:
Hi again,
Now if I may ask of one mor thing, while the jumping is smooth now, I
notice that occasionally when I start jumping it’ll spike a little
higher then resume going a constant hieght. I think this has to do
with the timing I’m trying to impliment (the 'int true_accel = accel
- tick_delta/10;’ line). I devided by 10, when I oriiginally thought
to use 1000 but that gave me decimal value and ends up being
interpreded as
- And I thought it best to avoid something like ‘while (ticks <
ticks_last + interval) ticks = SDL_GetTicks();’ which would limit the
fame to that much time. Is there any way to remedy this?I agree with David on this; using floating points is much more
accurate. Your code should calculate how many (fractional) seconds
passed since
the last frame, and calculate the movement based on this time delta.
Your velX and velY seem to be fixed on a per-frame basis, but each
frame could be different in length. But if your approach works, keep
it that way.
Well I’m seeking to improve my approuch. I’m not sure how to incorporate
the floating point i na useful manner, seeing that those information
gets lost somewhre along the line, since the finaly movement is done as
integers (as far as I know you can’t have half a pixel, or even if you
can, I don’t see how that can be done in SDL, seeing as the actualy
drawing (such as in my DrawIMG functions) is using SDL_BlitSurface,
which takes an SDL_Rect, whih uses ints.)
So maybe I’m missing your meaning. Do you mean perhaps to make
everything floats or doubles (vel’s, guy/move/X/Y, tick stuff) and then
let DrawIMG harvest the int part? I’m not sure hwo this wil lbe more
accurate when it’ll eventually be turned back into ints.
Oh, and you may want to change the guy’s velocity (now in the “//
Jump.” block) after the guy has moved, so you’ll get the full
max_velocity in the first frame of jumping.I’m not sure what you mean here? This doesn’t make sense to me. How
can the guy move before the velocity is set? Perhaps I’m not
understanding what you meant.No, not before it is set, before it is adjusted. In your (original)
"// Jump." block, you have a line
velY -= true_accel;
That’s the line I’m talking about. Move this more towards the back,
otherwise you will never use the full maximal velocity, only the
once-diminished form.
Ah, seems so clear now, it would substract first and ask questions
later. Thanks for claring that up. I don’t think I’ve had enough sleep
lately lol.–
Blaza