NOOB question - How do I get the frame count?
Moderator: Stef
-
- 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?
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!
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.
-
- 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?
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
Last edited by POLYGAMe on Mon Nov 11, 2019 9:44 am, edited 1 time in total.
Re: NOOB question - How to I get the frame count?
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.
-
- 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?
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?
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
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
-
- 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?
Ah yes, that sounds perfect. Thanks!
Re: NOOB question - How do I get the frame count?
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).
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".
-
- 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?
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.
But SGDK also own the frame counter into vtimer variable.
-
- 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?
LOL I'm an idiot. Was going over some previous code and I found this:
Ah, yup... that'll do it.
Sometimes I get hung up on the stupidest little thing. I need to stop overthinking these things.
Code: Select all
// Update v-sync counter
if (vBlankCounter >= 60)
{
vBlankCounter = 0;
}
else
{
vBlankCounter++;
}
Sometimes I get hung up on the stupidest little thing. I need to stop overthinking these things.