Am I doing this 'timing' stuff right?

SGDK only sub forum

Moderator: Stef

Post Reply
POLYGAMe
Very interested
Posts: 151
Joined: Sun Apr 14, 2013 1:19 am
Location: Auckland, New Zealand
Contact:

Am I doing this 'timing' stuff right?

Post by POLYGAMe » Mon Jan 04, 2016 3:24 am

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?

Post Reply