VSYNC in SmileBasic V1 is identical to that in V2. Also,
VSYNC can be used in place of
WAIT, which is not available in V1: the effects of
WAIT N can be achieved with
VSYNC 0:VSYNC N.
VSYNC is a command which takes one numerical parameter, which gets rounded down, and pauses execution of the program: in that respect, it is very similar to
WAIT, but the details differ.
When a program starts executing, and at the end of every
WAIT command, a clock is reset. Once every 1/60 of a second, i.e. once every frame, the physical displays are updated to reflect the current state of the display buffers, and at the same time, this clock is incremented. The
VSYNC command will wait until the value of this clock matches the command's parameter, if it has not reached or exceeded that value already. (A negative parameter will generate an
Out of range (VSYNC) error.) And when
VSYNC is finished, as already mentioned, the clock is reset to 0.
VSYNC 0 takes very little time.
VSYNC 1, when the clock is at 0, will wait for the next tick of the frame clock; when the clock is at 1 or more, it will take very little time.
VSYNC 2 when the clock is at 0 will wait 2 ticks, when the clock is at 1 will wait 1 tick, and when the clock is at 2 or above will take very little time.
A common use of
VSYNC is for reducing or eliminating animation flicker, and making gameplay smoother. Consider a typical game superloop: draw the current state of the game, calculate the next state of the game, repeat. If there is, say, a
VSYNC 5 just before the 'draw' code, this will ensure that one pass through the loop (from the beginning of one drawing phase, to the beginning of the next drawing phase) will never take less than 5 frames. If it is known that the draw and calculate sections together will never take more than 5 frames (and there are no other
WAIT commands), the command ensures that the update rate is once per 5 frames, exactly, always: if the loop, unsynchronized, would 2 frames sometimes, and 4 frames other times, the player will not notice any difference in gameplay when the appropriate
VSYNC is included. And if it takes less than one frame to complete the draw phase, and it is immediately after the
VSYNC, the display will never show a half-drawn image.
VSYNC N waits until the clock reaches
N if it has not already, and resets the clock. If it does wait, it terminates on a frame clock 'tick', which is the best time to start drawing.
No information on SmileBasic V3.