How would I make a game loop?

It’s been a very long time since I last used cocos2d-x, so I’ve forgotten a lot of things. I’ve been searching for a while now how to make a game loop, but all the tutorials I found were outdated. How could I make a game loop in cocos2d-x 4.0?

I figured it out, for anyone that’s here and needs help:
Call scheduleUpdate(); in your init function
Define void update(float delta); in your .h file

void SceneName::update(float delta) { // Change SceneName to your scene name

to your code.
Put your code in the function, and you have a game loop!
I recommend you multiply numbers by delta. Delta is how much time it has been since the last frame,
multiplying numbers by it helps prevent people’s games running faster if they have high framerate

This is the way I create “main” game loop so you have control.

Set some Global Var’s or stick them in your HelloWorld class and set the class setName(“HelloWorld”);
then you call auto hello = static_cast<HelloWorld*>(getChildByName(“HelloWorld”));
to get access from anywhere in cocos engine.

//Global Var’s
#define GAME_UPDATE 0
#define GAME_PAUSE 1
#define GAME_MENU1 2
#define GAME_MENU2 3
#define GAME_EXIT 4
static int gameState = 0;

Then in your loop create a switch case to control the game state so if you in the menu your game will not update and run menu function’s simply by changing the gameState.
this is how I control my main game thread.

void HelloWorld::update(float delta) {

switch (gameState) {



case GAME_MENU1:

case GAME_MENU2: