Page 1 of 1

Am I doing this 'timing' stuff right?

Posted: Mon Jan 04, 2016 3:24 am
by POLYGAMe
Hey guys and gals,

So here's some code to just flash text on screen. It works, just wondering if this is the way you generally handle stuff, waiting for the v-blank, rather than some sort of delta time (as I am used to doing in Unity)? Is that a correct assumption? Sorry if this is noobish, haven't touched C in AAAAGES.

Code: Select all

#include <genesis.h>

int main()
{

    int vBlankCounter = 0;
    int vPos = 2;
    int hPos = 2;
    int isFlashing = 0;

    VDP_drawText("FLASHING TEXT", vPos, hPos);

    while(1)
    {
        VDP_waitVSync();

        if (vBlankCounter >= 60)
        {
            if (isFlashing == 0)
            {
                VDP_clearTextLine(vPos);
                isFlashing = 1;
            }
            else
            {
                VDP_drawText("FLASHING TEXT", vPos, hPos);
                isFlashing = 0;
            }

            vBlankCounter = 0;
        }
        else
        {
            ++vBlankCounter;
        }
    }

    return (0);
}
Am I on the right track?