Skip to main content

(VI) Frame control & locking the screen while drawing: screensync, cls, screenlock, screenunlock

Hiya everybody!


Take a look at the code of the day:

Let me explain the new keywords used:
  • screensync is the key to take the number of frames per second under control because this instruction waits until next refresh of the screen, usually 60 times per second known as 60 fps. After this we will draw our screen.
  • cls to CLear the Screen and draw from zero the new state of the game.
  • screenlock to lock the screen to hide it while we are drawing.
  • screenunlock to unlock the screen to show the new drawed screen.
Is very important to respect that we have to draw inmediately after the screensync and remember that between screenlock and screenunlock you have to draw, nothing else to do this part of the code as fast as possible.

How is the structure? more and more accurate every time:
  • DESCRIPTION
  • DECLARATIONS
  • INITIALIZATIONS
  • GAME LOOP
    • INPUT
    • DO UPDATE
    • DRAW
      • screensync
      • screenlock
      • cls
      • ...
      • screenunlock
    • FREE UP CPU TIME
      • sleep 1,1
  • ENDING
This is enough by now, we are ready to see in the next entry how to control and move the white square.

Contact me for any question and tell me your feedback, see you!

Go to the next entry
Go to the previous entry
Go to the first entry

Comments

Popular posts from this blog

(II) Download & setup FreeBASIC's IDE FBIde

Hi everybody! If you use Microsoft Windows on your computer you can download FBIde from SourceForge in this link:  https://sourceforge.net/projects/fbide/files/ Go to fbide 0.4 folder and then fbide 0.4.6 r4  folder and download the zip file with the name  FBIde0.4.6r4.zip . Note: 0.4.6 r4 is the last version while doing this blog entry. Now decompress downloaded file in the path you desire. Me I decided to use my Desktop, beside my FreeBASIC compiler and help folders. Go into  FBIde0.4.6r4  folder and execute the application  fbide Click Yes in the message window. And search fbc application inside your FreeBASIC's compiler folder to open it. Go to View/Settings to Choose your Theme for the editor, I like obsidian theme. Add some new Keywords in Group 2 . Choose the path for FreeBASIC Help file (.chm) downloaded in the previous entry of this blog. Remember to click OK to submit the changes. This is e nough by now, i...

(I) Download FreeBASIC compiler & help

Welcome everybody! You can download FreeBASIC from SourceForge in this link:  https://sourceforge.net/projects/fbc/files/ If you use Microsoft Windows on your computer you can go to Binaries - Windows folder and download the zip file with the name FreeBasic-1.07.1-win32.zip that will run both 32 and 64 bits systems. Note: 1.07.1 is the last version while doing this blog entry. We will also download the help file going back and entering the folder Documentation and downloading the zip file FB-manual-1.07.1-chm.zip Now decompress both downloaded files in the path you desire. Me I decided to use my desktop. Go into FreeBASIC-1.07.1-win32  folder and create a Projects folder that we will use to save our programs and their resources. This is enough by now, in the next entry we will download and setup our IDE to write and run our programs. Contact me for any question, see you! Go to the next entry

(III) Make an screen to play: ', const as integer, screenres, sleep & end

Come on everybody! Let's see our first code to make an screen to play. Let me explain the keywords used: '   t o add comments to the code, very useful to understand even the code made by ourselves. Used alone in a row or at the end of an instruction. const as integer to declare labels as integer numbers that contain constant values, non modifiable along the program. In this case w and h are constants. We must separate different consts with comma. screenres to do an screen to play, we have to tell two parameters the width and the height of the screen. We must separate parameters with comma. sleep to wait until a key is pressed to see the screen that otherwise will close too fast. end to end the program.  And the structure of this code not too far from the structure of a larger one: DESCRIPTION DECLARATIONS INITIALIZATIONS Main code ENDING In FBIde you can run the code pressing function key F5 or clicking Quick run icon This is the result of our ...