i have no idea how to get my sprite moving smoothly. If you know what i am doing wrong, i would greatly appreciatte your advice! I'm using SDL and it is a very basic program.
Werdy666
i have no idea how to get my sprite moving smoothly. If you know what i am doing wrong, i would greatly appreciatte your advice! I'm using SDL and it is a very basic program.
Werdy666
1. Your DeltaTime function isn't returning a konstant value. How can you expect your object to move at an even pace when your incrementing the xpos with a different int each time. Try setting xpos += 1; in your main loop. See the difference?
2. You should read through all the cone 3d tutorials before you attempt to make objects move on their own. I noticed you're still blitting the entire background on each pass. This is very expensive. The proper technique is to only blit the minimum amout of background needed to clear the old object.
Last edited by Invincible; 05-30-2002 at 01:38 PM.
"The mind, like a parachute, only functions when open."
hi,
ok what i did was made sure it would move no more than 1 pixel each movement, and also reduced the bitmap to 16x16, so my blitting should be a whole lot faster now.
here is my main game loop as it stands now...
I also made it 16 bit color. However it is still moving what i would call slow. It takes around 15 seconds to go across 320 pixels.Code:int done=0; while(done == 0) { currentTime = SDL_GetTicks(); SDL_Event event; while ( SDL_PollEvent(&event) ) { if ( event.type == SDL_KEYDOWN ) { if ( event.key.keysym.sym == SDLK_ESCAPE ) { done = 1; } } } if( currentTime - lastTime > 50.0 ) // ie after 50 milli seconds { lastTime = currentTime; xpos+=1 ; //increments the value of xpos by 1 } DrawScene(); SDL_Flip(screen); }
If I change the 50 milliseconds to 0, then it takes about 6 seconds to go across the full 640 pixels.
That is where i have seen other games made by your average programmer, move bitmaps at a much faster speed, but still being smooth movement. Any other ideas how i can make my bitmap move fast and smooth?
Mind uploading your full source so I can look at again?
"The mind, like a parachute, only functions when open."
not a problem. Here is my full source!
Ok ... it looks ok to me for the most part. Here are a few things I noticed.
I don't know why you're assigning float to your (x, y) positions when the SDL_rect structure variables are of type int. In other words change them to int.
SDL_GetTicks() takes returns an unsigned integer, not a float. Use Uint8, Uint16, or Uint32. I'm not certain which one works best with the function.
I'm not certain your timing function is set up correctly although its a better attempt than I could have come up with. I can't really help you here because I'm trying to learn how to do it myself right now. I will tell you though that I've read that library time functions are unreliable. Some claim that the proper and most accurate way to control program speed over various processors is to use some kind of hardware interrupt through assembler that I don't understand yet.
Edit:
Maybe you don't need assembley. Have you seen this post:
http://www.cprogramming.com/cboard/s...ighlight=speed
Last edited by Invincible; 05-31-2002 at 03:32 AM.
"The mind, like a parachute, only functions when open."