NOOB question - How do I get the frame count?

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:

NOOB question - How do I get the frame count?

Post by POLYGAMe » Mon Nov 11, 2019 12:36 am

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!
Last edited by POLYGAMe on Mon Nov 11, 2019 9:43 am, edited 1 time in total.

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

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

Post by POLYGAMe » Mon Nov 11, 2019 6:30 am

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
Last edited by POLYGAMe on Mon Nov 11, 2019 9:44 am, edited 1 time in total.

hotrodx
Very interested
Posts: 50
Joined: Thu Mar 21, 2019 1:23 pm

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

Post by hotrodx » Mon Nov 11, 2019 7:20 am

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.

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

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

Post by POLYGAMe » Mon Nov 11, 2019 9:41 am

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.

hotrodx
Very interested
Posts: 50
Joined: Thu Mar 21, 2019 1:23 pm

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

Post by hotrodx » Mon Nov 11, 2019 11:03 am

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

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

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

Post by POLYGAMe » Mon Nov 11, 2019 11:43 am

Ah yes, that sounds perfect. Thanks!

Sik
Very interested
Posts: 939
Joined: Thu Apr 10, 2008 3:03 pm
Contact:

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

Post by Sik » Mon Nov 11, 2019 6:15 pm

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).
Sik is pronounced as "seek", not as "sick".

Stef
Very interested
Posts: 3131
Joined: Thu Nov 30, 2006 9:46 pm
Location: France - Sevres
Contact:

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

Post by Stef » Tue Nov 12, 2019 5:17 pm

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.

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

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

Post by POLYGAMe » Mon Nov 18, 2019 2:08 am

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.

Post Reply