Open a screen

Screen are the first step to make a game, on the screen we can draw sprites and other type of elements to make our game, this tutorial show main steps to open a screen. For this tutorial example we need a variable called Quit, and other for the screen identifier called hScreen.


 Declare Quit.b, hScreen.l

Then we can initialise DirectX and open our screen with OpenDXSreen() with size of 640x480 and 16 bits of colors:


  If InitDXSprite() != 0

    hScreen = OpenDXScreen(640, 480, 16, "VM Basic Screen tutorial") != 0 
  
    If hScreen != 0

Now we add a repeat block of code until user want to quit our program, processing the event with ProcessEvent(). We check also that the screen is actived with IsScreenActive() to not made drawing operations when the screen is minimized:


     Repeat 

       ProcessEvent() 

       If KeyPushed(#VMB_KEY_ESCAPE) = #True 
         Quit = #True 
       EndIf  

       If IsScreenActive(hScreen) = #True 
         FlipDXBuffers(#VMB_SCREEN_CLEAR, RGB(0, 0, 255)) 
       EndIf  

     Until Quit = #True

Now we must close the screen and put the EndIf for DirectX init check and for open screen check and end our program:


   CloseDXScreen()

   EndIf

 EndIf
 
 EndProgram  

Exercise:
Add commands necesary to wait 10 milleseconds every iteration if screen is not activated, to don't consume a lot of CPU usage when it is minimized.