10.03.2019 - Round 1 results of our "A Love Letter For FreeBASIC" game dev competition have been published. Please be sure to check the results thread: http://games.freebasic.net/forum/index.php?topic=629.0. Don't forget that the competition is continuing with a round 2, lasting till 29th of April, 300 USD first prize. Stay tuned!

### Author Topic: Smooth movement  (Read 5038 times)

#### Tusike

• Novice
• Posts: 95
##### Smooth movement
« on: June 16, 2010, 08:15:17 AM »
Hey!

Can anyone tell me how I can run this simple program in which a ball moves around the screen, and make the movement smooth? Right now it like sometimes seems to go faster, then slower, all in all the movement is definitely not smooth. I've played games in which they had things move much faster, and still it appeared to be smoother.

@Kristopher: I know you're making a breakout game (how's that going on by the way?), so perhaps you can tell me how you handled the ball movement.

Thanks!

Here's the code:

Code: [Select]
`screenres 1280, 800, 24,,1const dt = .005dim as double t = 0.0, currentTime, newTime, accumulator, deltaTimedim as single frames, fpsdim as single bx, by, bvx, bvydim as integer brbx = 500by = 500bvx = int(rnd * 300) + 150bvy = int(rnd * 300) + 150br = 10currentTime = timeraccumulator = 0.0do    newTime = timer    deltaTime = newTime - currentTime       currentTime = newTime        accumulator += deltaTime        while (accumulator>=dt)                bx += bvx * dt        by += bvy * dt                if bvx < 0 and bx - br < 0 then bvx *= -1: bx += bvx*dt        if bvx > 0 and bx + br > 1279 then bvx *= -1: bx += bvx*dt        if bvy < 0 and by - br < 0 then bvy *= -1: by += bvy*dt        if bvy > 0 and by + br > 799 then bvy *= -1:by += bvy*dt                t += dt        accumulator -= dt            wend    screenlock    line (0, 0) - (1279, 799), rgb(20, 20, 80), BF       circle (bx, by), br, rgb(200, 80, 20),,,,F         screenunlock    sleep 1loop while inkey <> chr(27)sleep`

#### mambazo

• Recruit
• Posts: 35
##### Re: Smooth movement
« Reply #1 on: June 19, 2010, 08:17:25 PM »
I don't think its possible on some setups.

Windows XP and gfxlib2 have always had the jitters for me. OpenGL seems to work well though, maybe its to do with hardware acceleration?

#### Tusike

• Novice
• Posts: 95
##### Re: Smooth movement
« Reply #2 on: June 20, 2010, 12:41:38 AM »
I don't know OpenGL. But I did post this up on the freebasic forum, and it turned out adding "screensync" makes it work fine. Consider this thread closed.

-Tusike

#### KristopherWindsor

• Forum Sage
• Posts: 363
• The Thirsty Smiley
##### Re: Smooth movement
« Reply #3 on: June 23, 2010, 05:54:00 PM »
I could never get really smooth motion on Vista / 7, but most people probably wouldn't notice. Screensync didn't work for me, but really some computers looked smoother than others. Ideally you want exactly 60FPS, so in your case I think you want to sleep longer, but it still won't look perfect.
FWIW I used the GDI mode in Ultrabreaker due to other issues. The game isn't getting finished anytime soon; I'm interning at Facebook this summer.