Do you need tutorials ?

SGDK only sub forum

Moderator: Stef

titoalc
Newbie
Posts: 1
Joined: Mon Mar 08, 2021 5:55 am

Re: Do you need tutorials ?

Post by titoalc » Sun Jan 16, 2022 4:16 am

I want create a timer event when countdown is 0 do something i dont know how use this

AmateurSegaDev
Newbie
Posts: 4
Joined: Sun Feb 27, 2022 3:27 am

Re: Do you need tutorials ?

Post by AmateurSegaDev » Sat May 21, 2022 4:10 pm

I have no idea if this is the best approach (I'm learning C simultaneously), but here is what I've done to control some animations:


I have an animationTimer variable that I increment at the very end of my main() function.

Code: Select all

if (animationTimer > 59){
          animationTimer = 0;
        }
        else{
          animationTimer++;
        }
}
Then, I pass it along with a "state variable" as pointers into my desired function so I can reset it when I perform whatever action I was waiting on the timer for:

Code: Select all

void myFunction(u8 *animationTimer, u8 *functionState){
     switch(*functionState)){
          case functionReady:
               *animationTimer = 0; //Prepare Timer
               *functionState = functionDoStuff;  //Advance case.
          case functionDoStuff:
               int timerEventVaue = 15;
               if (*animationTimer > timerEventValue){
                    *animationTimer = 0;
                    //Do Stuff
                    *functionState = functionReady;  //Reset the case.
               }
         break;
         }
}

Post Reply