Thread: could someone tell me what i am doing wrong???

  1. #1
    Registered User
    Join Date
    May 2002
    Posts
    33

    Unhappy could someone tell me what i am doing wrong???

    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

  2. #2
    Registered User Invincible's Avatar
    Join Date
    Feb 2002
    Posts
    210
    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."

  3. #3
    Registered User
    Join Date
    May 2002
    Posts
    33
    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...
    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);
    	}
    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.

    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?

  4. #4
    Registered User Invincible's Avatar
    Join Date
    Feb 2002
    Posts
    210
    Mind uploading your full source so I can look at again?
    "The mind, like a parachute, only functions when open."

  5. #5
    Registered User
    Join Date
    May 2002
    Posts
    33
    not a problem. Here is my full source!


  6. #6
    Registered User Invincible's Avatar
    Join Date
    Feb 2002
    Posts
    210
    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."

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Replies: 9
    Last Post: 07-15-2004, 03:30 PM
  2. Debugging-Looking in the wrong places
    By JaWiB in forum A Brief History of Cprogramming.com
    Replies: 1
    Last Post: 11-03-2003, 10:50 PM
  3. Confused: What is wrong with void??
    By Machewy in forum C++ Programming
    Replies: 19
    Last Post: 04-15-2003, 12:40 PM
  4. God
    By datainjector in forum A Brief History of Cprogramming.com
    Replies: 746
    Last Post: 12-22-2002, 12:01 PM
  5. Whats wrong?
    By Unregistered in forum C Programming
    Replies: 6
    Last Post: 07-14-2002, 01:04 PM