Page 1 of 1

NOOB question - How do I get the frame count?

Posted: Mon Nov 11, 2019 12:36 am
by POLYGAMe
Hi there,

I'm trying to work out basic timers for my game. How exactly do I get hold of the V blank/frame count? I've had a look in the docs but I can't find anything. Basically I have a player pitching a ball and I want to stop them from moving for a short amount of time after the ball is pitched.

Cheers!

Re: NOOB question - How do I get the frame count?

Posted: Mon Nov 11, 2019 6:30 am
by POLYGAMe
Managed to get it working with a timer and a bool but would still like to know how to grab the frame count as subticks are a bit messier - I just want to deal in frames per second, not huge numbers that baffle my tiny brain :D

Re: NOOB question - How to I get the frame count?

Posted: Mon Nov 11, 2019 7:20 am
by hotrodx
I haven't used them myself, but there's SYS_getFPS in sys.c and getSubTick in timer.c. Might be what you're looking for.

Re: NOOB question - How do I get the frame count?

Posted: Mon Nov 11, 2019 9:41 am
by POLYGAMe
Yeah I'm using subticks but I just want to use actual frames. The fps doesn't help as I need an actual count of frames so I can do something every x amount of frames rather than the amount of frames per second as that's probably always going to be 60 in this game.

Re: NOOB question - How do I get the frame count?

Posted: Mon Nov 11, 2019 11:03 am
by hotrodx
You could increment a variable every vsync, then use modulo so it "wraps" around at specific intervals.

So something like:
i++;
wait_vsync();
i%=60;
if (i == 0) doSomething(); // fires every 60 ticks or ~1 second

The SPRITE structure has a time value that is decremented on SPR_update. If it reaches 0, it moves to the next frame.

If you created the sprite sheet, and handcrafted your SPRITE.res, you can count how many ticks a whole animation uses. In this example:

SPRITE sonic_sprite "sprite/sonic.png" 6 6 FAST 5

A frame lasts 5 ticks (the 4th value). So for example if Sonic's run animation is 10 frames, then it takes 10 * 5 = 50 ticks for the whole animation sequence.

When you have your player's animation started, set a variable to 0 then increment every game loop. If it reaches the computed cycle, then do your action (switch to another animation, or to a single frame animation that matches the last frame so it holds until you change it).

Edit: correction

Re: NOOB question - How do I get the frame count?

Posted: Mon Nov 11, 2019 11:43 am
by POLYGAMe
Ah yes, that sounds perfect. Thanks!

Re: NOOB question - How do I get the frame count?

Posted: Mon Nov 11, 2019 6:15 pm
by Sik
Yeah, sounds like you ended up looking something completely unrelated (・ω・;)

Your own counters that go up every frame (like there) is the way to go, regardless of platform. Remember to not increment it while the game is paused. In a complex game you probably will even have multiple of those for different things (not to mention counters that sometimes freeze, or sometimes go faster, or backwards, etc. all entirely at your whim).

Re: NOOB question - How do I get the frame count?

Posted: Tue Nov 12, 2019 5:17 pm
by Stef
Timer unit give a method to retrieve elapsed time from hard reset (SYS_getTimer() or something like that).
But SGDK also own the frame counter into vtimer variable.

Re: NOOB question - How do I get the frame count?

Posted: Mon Nov 18, 2019 2:08 am
by POLYGAMe
LOL I'm an idiot. Was going over some previous code and I found this:

Code: Select all

    // Update v-sync counter
    if (vBlankCounter >= 60)
    {
        vBlankCounter = 0;
    }
    else
    {
        vBlankCounter++;
    }
Ah, yup... that'll do it.

Sometimes I get hung up on the stupidest little thing. I need to stop overthinking these things.