Jump to content
  • Advertisement
Sign in to follow this  
Amnesty2

2D movement trouble

This topic is 2601 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Hello, im working a game. I've been programming for a long time but this is the first time doing graphics programming.
Im having trouble making the movement of my space invaders look good.

The invaders move downward pretty nicely. But adding any movement along the x-axis is really choppy and poor. The invader will move straight down for 20 pixels smoothly and then just jump right or left; when it should be just a smooth slope.

this is the invaders update function.. It is also responsible for drawing the invader

void invader::update(Timer& time)

{



if (_time == 0)

_time = time.get_ticks();



if(is_alive)

{

_y = _y + ((time.get_ticks() - _time) * .10);

_x = _x + ((time.get_ticks() - _time) * .05);





_time = time.get_ticks();

// Apply texture

}

[font="Calibri"]}[/font]



This is my game loop.. Its very small as i've dumbed it down .. Only one invader and nothing else.. It still has the same trouble.

[font="Calibri"] [/font]

//While the user hasn't quit

while( quit == false )

{

//While there's an event to handle

while( SDL_PollEvent( &event ) )

{

//If the user has Xed out the window

if( event.type == SDL_QUIT )

{

//Quit the program

quit = true;

}



}



//Increment the frame counter

frame++;



//Apply the background to the screen

apply_surface( 0, 0, background, screen );



invader_guy->update(fps);



//Update the screen

if( SDL_Flip( screen ) == -1 )

{

return 1;

}



//If we want to cap the frame rate

if( ( cap == true ) && ( fps.get_ticks() < 1000 / FRAMES_PER_SECOND ) )

{

//Sleep the remaining frame time

SDL_Delay( ( 1000 / FRAMES_PER_SECOND ) - fps.get_ticks() );

}





}






The timer class is lazyfoos it just makes SDL_GetTicks more useful by giving the elapsed ticks not the total.
It uses

Any ideas, thoughts or demo on proper 2D movements with velocitys and timers would be much much appreciated!

Share this post


Link to post
Share on other sites
Advertisement
Try playing with the x movement variables, to see if you can get a more fluid movement. i.e. try making it move a shorter distance per frame.

If this movement becomes too slow, you could always increase the frame rate, which is just a tweak to a const int if you are using Lazy Foo's refresh method.

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!