Hello Guest

Display.sync();

  • 5 Replies
  • 7948 Views
Display.sync();
« on: July 13, 2012, 14:35:35 »
can you explain what the method Display.sync(60) doing?
its set a 60 frame per second or stop/rest for 60 frame per second?

*

Offline kappa

  • *****
  • 1315
Re: Display.sync();
« Reply #1 on: July 13, 2012, 16:43:49 »
Display.sync(60) will try to run your game at a constant frame rate of 60 fps. Its a method that you need to call once every frame (i.e. it should be in your game loop). Firstly the method calculates the amount of time it needs to sleep every frame (i.e. 1 second / 60 which is about 16 milliseconds) it then calculates the amount of time that has passed since the last time it was called, if the time passed is less than 16ms it then sleeps for the remainder of that time otherwise it does nothing.

*

Offline moci

  • *
  • 27
    • mathiasverboven.net
Re: Display.sync();
« Reply #2 on: July 13, 2012, 16:58:29 »
Is it actually a constant 60? If I'm moving/resizing/... my window it will drop somewhat. Maybe my FPS calculation function is a bit off, but I find that it is close to whatever value you use (60 in this case) but not exactly. I really use it to limit the workload of my GPU as there is no need to run at 5000 fps (and heat up the GPU).

Re: Display.sync();
« Reply #3 on: July 13, 2012, 17:03:45 »
Its mean that if i wirte this code, so if the progrem did 60 frame in a half of a second(for example right, real its take 16 ms)so the rest of the second that mean another half of a second he will "sleep"? thats mean he have to do 60 frame and after he did that he can "Sleep" all the rest of the second that left him? am i right? :D

*

Offline kappa

  • *****
  • 1315
Re: Display.sync();
« Reply #4 on: July 13, 2012, 18:00:22 »
Its mean that if i wirte this code, so if the progrem did 60 frame in a half of a second(for example right, real its take 16 ms)so the rest of the second that mean another half of a second he will "sleep"? thats mean he have to do 60 frame and after he did that he can "Sleep" all the rest of the second that left him? am i right? :D
No that understanding of how Display.sync() works is incorrect, the 60 frames will not display as quickly as possible, instead it will take about 16ms to draw each frame (i.e. time it actually took to draw the the frame + sleeping to make it a total of about 16ms) therefore it will take a full second to draw 60 frames.

Re: Display.sync();
« Reply #5 on: July 13, 2012, 19:15:32 »
thats mean he actually divides a second in 60 and its the time he will draw one frame? in this time he sleep too or when you draw or making things slowly not onerous the resources thats mean he dont have to sleep?
and what about vsync what hes doing? :O

by the way thank you and sorry about my question i'm just wanna know the subject a best as i can :D
« Last Edit: July 13, 2012, 19:19:49 by Yarin1312 »