Skip to main content
deleted 1 character in body
Source Link
rxjsisfine
  • 321
  • 1
  • 3
  • 8

I want to know to code structure of a game that has different levels to choose from on the main screen. More precisely, I want to know how does the main loop hands off the rendering to another loop that exist in the level code.

I could think of a solution but I would like to know how this is done buyby game developers.

Solution:

// Level.cpp
void Level::LevelLoop() {
    while(LevelNotDone){
        handleInput();
        update();
        render();
    }
}

// Main.cpp
void MainLoop() {
    while(GameNotDone){
        handleInput();
        
        if (Condition to start level)
            level.LevelLoop();
        
        // wait until level loop exits
        
        update();
        render();
    }
}

I want to know to code structure of a game that has different levels to choose from on the main screen. More precisely, I want to know how does the main loop hands off the rendering to another loop that exist in the level code.

I could think of a solution but I would like to know how this is done buy game developers.

Solution:

// Level.cpp
void Level::LevelLoop() {
    while(LevelNotDone){
        handleInput();
        update();
        render();
    }
}

// Main.cpp
void MainLoop() {
    while(GameNotDone){
        handleInput();
        
        if (Condition to start level)
            level.LevelLoop();
        
        // wait until level loop exits
        
        update();
        render();
    }
}

I want to know to code structure of a game that has different levels to choose from on the main screen. More precisely, I want to know how does the main loop hands off the rendering to another loop that exist in the level code.

I could think of a solution but I would like to know how this is done by game developers.

Solution:

// Level.cpp
void Level::LevelLoop() {
    while(LevelNotDone){
        handleInput();
        update();
        render();
    }
}

// Main.cpp
void MainLoop() {
    while(GameNotDone){
        handleInput();
        
        if (Condition to start level)
            level.LevelLoop();
        
        // wait until level loop exits
        
        update();
        render();
    }
}
deleted 1 character in body
Source Link
rxjsisfine
  • 321
  • 1
  • 3
  • 8

I want to know to code structure of a game that has different levels to choose from on the main screen. More precisely, I want to know how does the main loop hands off the rendering to another loop that exist in the level code.

I could think of a solution but I would like to know how this is done buy game developers.

Solution:

// Level.cpp
void Level::LevelLoop() {
    while(LevelNotDone){
        handleInput();
        update();
        render();
    }
}

// Main.cpp
void MainLoop() {
    while(LevelNotDoneGameNotDone){
        handleInput();
        
        if (Condition to start level)
            level.LevelLoop();
        
        // wait until level loop exits
        
        update();
        render();
    }
}

I want to know to code structure of a game that has different levels to choose from on the main screen. More precisely, I want to know how does the main loop hands off the rendering to another loop that exist in the level code.

I could think of a solution but I would like to know how this is done buy game developers.

Solution:

// Level.cpp
void Level::LevelLoop() {
    while(LevelNotDone){
        handleInput();
        update();
        render();
    }
}

// Main.cpp
void MainLoop() {
    while(LevelNotDone){
        handleInput();
        
        if (Condition to start level)
            level.LevelLoop();
        
        // wait until level loop exits
        
        update();
        render();
    }
}

I want to know to code structure of a game that has different levels to choose from on the main screen. More precisely, I want to know how does the main loop hands off the rendering to another loop that exist in the level code.

I could think of a solution but I would like to know how this is done buy game developers.

Solution:

// Level.cpp
void Level::LevelLoop() {
    while(LevelNotDone){
        handleInput();
        update();
        render();
    }
}

// Main.cpp
void MainLoop() {
    while(GameNotDone){
        handleInput();
        
        if (Condition to start level)
            level.LevelLoop();
        
        // wait until level loop exits
        
        update();
        render();
    }
}
Source Link
rxjsisfine
  • 321
  • 1
  • 3
  • 8

Designing a multi-level game

I want to know to code structure of a game that has different levels to choose from on the main screen. More precisely, I want to know how does the main loop hands off the rendering to another loop that exist in the level code.

I could think of a solution but I would like to know how this is done buy game developers.

Solution:

// Level.cpp
void Level::LevelLoop() {
    while(LevelNotDone){
        handleInput();
        update();
        render();
    }
}

// Main.cpp
void MainLoop() {
    while(LevelNotDone){
        handleInput();
        
        if (Condition to start level)
            level.LevelLoop();
        
        // wait until level loop exits
        
        update();
        render();
    }
}