Anonymous asked in Computers & InternetProgramming & Design · 6 years ago

How to display a level in video game programming?

i'm wondering how the level is displayed ingame ?

a entire level is made of many screens but you can only display one screen at a time

so how to do that in c++?

1 Answer

  • mike
    Lv 4
    6 years ago
    Best Answer

    Simple solution is to put each screen into an array of screens, then simply display the current screen you want to be shown by using the subscript operator( The `[]' ). Such as:

    GRenderingDevice_Scr* screens[<num_of_screens>];

    // assign your screens here.

    assignMyScreens(screen, <num_of_screens>);

    unsigned int active_screen = 0; // The first screen -- change this to the index of which the screen that is to // be displayed

    if(screens[active_screen] != 0x0)


    // Example

    void assignMyScreens(GRenderingDevice_Scr* screens, unsigned int count){

    for(unsigned int i = 0; i < count; i++){

    screens[i] = new GRenderingDevice_Scr(BLAH BLAH BLAH);



    The way the level's draw code is written depends on how you wrote the code to handle displaying.

    Typically if screen array has a static number(the screen count does not change) you can assign each screen's index to a name using enum:

    enum ScreenIndex{






    GRenderingDevice_Scr* screens[SCREEN_NUM];

    // assign your screens here.

    assignMyScreens(screen, SCREEN_NUM);

    ScreenIndex activeScreen = SCREEN_0;

    if(screens[SCREEN_0] != 0x0)


    If you have a screen count that changes consider using the std::list or std::vector.

    With all honesty if you cannot understand this code you should not be writing games in C++. Unless the game is a console game or some sort of basic UI game.

    I used something similar when I was making a small game with mini-sub games, but I had to write it so only one game can play at a time instead of all of em'.

Still have questions? Get your answers by asking now.