### GX Build Output Example Source: https://github.com/boxgaming/gx/wiki/Getting-Started Example output from the GX build script, indicating successful compilation of QB64 code into C++ and then into an executable. ```text QB64 Compiler V2.0.2 Beginning C++ output from QB64 code... Beginning C++ output from QB64 code... [..................................................] 100% Compiling C++ code into executable... ``` -------------------------------- ### Start Game Loop and Exit on ESC Key Press (VB) Source: https://github.com/boxgaming/gx/wiki/GXSceneStart This example demonstrates how to create a scene, start the game loop using GXSceneStart, and exit the loop when the ESC key is pressed. It also shows how to handle game events like updates and key presses within the GXOnGameEvent subroutine. ```vb '$INCLUDE: 'gx.bi' GXSceneCreate 320, 200 GXSceneStart PRINT "Game Over" SUB GXOnGameEvent (e AS GXEvent) SELECT CASE e.event CASE GXEVENT_UPDATE IF GXKeyDown(GXKEY_ESC) THEN GXSceneStop END SELECT END SUB '$INCLUDE: 'gx.bm' ``` -------------------------------- ### Create Game Scene Source: https://github.com/boxgaming/gx/wiki/Tutorial Creates a new game scene with specified dimensions. This is typically the first setup step for a GX game. ```vb '$Include: '../../gx/gx.bi' GXSceneCreate 320, 180 Sub GXOnGameEvent (e As GXEvent) End Sub '$Include: '../../gx/gx.bm' ``` -------------------------------- ### GX2Web Conversion Output Example Source: https://github.com/boxgaming/gx/wiki/Publish-to-Web Sample output from the gx2web converter, showing the process of converting a QB64 game ('overworld') to Javascript, copying assets like images and sounds, and preparing web framework files. ```text C:\Basic\projects\gx\tools>gx2web ..\samples\overworld\overworld.bas Converting game [overworld] from source [overworld.bas] in directory [..\samples\overworld]... Preparing output directory [C:\Basic\projects\gx\tools\dist\overworld] Converting QB64 to Javascript... 1 file(s) copied. Copying images... ..\samples\overworld\img\character.png ..\samples\overworld\img\coin.png ..\samples\overworld\img\fire.png ..\samples\overworld\img\flag.png ..\samples\overworld\img\objects.png ..\samples\overworld\img\overworld.png 6 file(s) copied. Copying sounds... Converting maps... -> overworld.gxm Copying web framework... C:\Basic\projects\gx\tools\web\dev.html C:\Basic\projects\gx\tools\web\fullscreen.png C:\Basic\projects\gx\tools\web\gx-logo.png C:\Basic\projects\gx\tools\web\gx.js C:\Basic\projects\gx\tools\web\index.html C:\Basic\projects\gx\tools\web\play.png C:\Basic\projects\gx\tools\web\qb64.js C:\Basic\projects\gx\tools\web\test.html C:\Basic\projects\gx\tools\web\qb64\font.png 9 File(s) copied C:\Basic\projects\gx\tools\dist\overworld\gx tmp\__gx_font_default.png tmp\__gx_font_default_black.png 2 file(s) copied. ``` -------------------------------- ### Set QB64 Home Environment Variable (Windows) Source: https://github.com/boxgaming/gx/wiki/Getting-Started Sets the QB64 installation directory as an environment variable on Windows. This is required for the build script to locate the QB64 compiler. ```batch > set QB64_HOME=C:\basic\qb64 ``` -------------------------------- ### Set QB64 Home Environment Variable (MacOS/Linux) Source: https://github.com/boxgaming/gx/wiki/Getting-Started Sets the QB64 installation directory as an environment variable on MacOS and Linux. This is necessary for the build script to find the QB64 compiler. ```shell > export QB64_HOME=~/qb64 ``` -------------------------------- ### JavaScript Function to Start the Game Source: https://github.com/boxgaming/gx/blob/main/tools/web/index.html A JavaScript function that hides the game's loading screen and initializes the game. It prevents default link behavior. ```javascript function startGame() { document.getElementById("gx-load-screen").style.display = "none"; init(); return false; } ``` -------------------------------- ### Get Scene Columns (Visual Basic) Source: https://github.com/boxgaming/gx/wiki/GXSceneColumns This example demonstrates how to retrieve the number of tile columns in the scene using the GXSceneColumns function in Visual Basic. The result is stored in an integer variable. ```vb DIM sceneCols AS INTEGER sceneCols = GXSceneColumns ``` -------------------------------- ### Check for ESC Key Press Source: https://github.com/boxgaming/gx/wiki/GXKeyDown This example demonstrates how to use GXKeyDown to detect when the ESC key is pressed. It initializes a game scene, starts the game loop, and exits the loop when the ESC key is detected within the game event handler. ```vb '$INCLUDE: 'gx.bi' GXSceneCreate 320, 200 GXSceneStart PRINT "Game Over" SUB GXOnGameEvent (e AS GXEvent) SELECT CASE e.event CASE GXEVENT_UPDATE IF GXKeyDown(GXKEY_ESC) THEN GXSceneStop END SELECT END SUB '$INCLUDE: 'gx.bm' ``` -------------------------------- ### Get Fullscreen Status (GXFullScreen) Source: https://github.com/boxgaming/gx/wiki/Methods Retrieves or sets the fullscreen mode of the application. When enabled, the scene content expands to cover the entire screen. Defaults to false. ```gx GXFullScreen(state = true) ``` -------------------------------- ### Get Current Frame Count (GXFrame) Source: https://github.com/boxgaming/gx/wiki/Methods Returns the current frame number. This counter begins at zero when GXSceneStart is invoked and increments with each frame. ```gx GXFrame() ``` -------------------------------- ### Draw Scene in QB64 GUI Event Loop Source: https://github.com/boxgaming/gx/wiki/GXSceneDraw This example demonstrates how to integrate GXSceneDraw into a QB64 GUI project, specifically within the event loop to handle scene updates and drawing. It ensures the scene is drawn correctly when the GUI manages the event loop. ```vb ... SUB __UI_BeforeUpdateDisplay GXSceneUpdate GXSceneDraw END SUB ... SUB GXOnGameEvent (e AS GXEvent) IF e.event = GXEVENT_PAINTBEFORE THEN BeginDraw PictureBox1 IF e.event = GXEVENT_PAINTAFTER THEN EndDraw PictureBox1 END SUB ... ``` -------------------------------- ### Get Map Height (GXMapRows) Source: https://github.com/boxgaming/gx/wiki/Methods Returns the height of the map, specified in tile rows. ```gx GXMapRows() ``` -------------------------------- ### Animate Entity with GXEntityAnimate (Visual Basic) Source: https://github.com/boxgaming/gx/wiki/GXEntityAnimate This example demonstrates how to create an entity using GXEntityCreate and then animate it using the GXEntityAnimate function. It defines animation sequences and sets the animation speed in frames per second. ```vb CONST SEQ_IDLE = 1 CONST SEQ_WALK_RIGHT = 2 CONST SEQ_WALK_LEFT = 3 GXSceneCreate 320, 200 DIM SHARED warhog AS LONG warhog = GXEntityCreate("img/warhog.png", 16, 16, 5) GXEntityAnimate warhog, SEQ_IDLE, 10 ``` -------------------------------- ### Get Scene Tile Rows in Visual Basic Source: https://github.com/boxgaming/gx/wiki/GXSceneRows Retrieves the number of tile rows in the scene using the GXSceneRows variable. This requires no specific dependencies beyond the GX library. ```vb DIM sceneRows AS INTEGER sceneRows = GXSceneRows ``` -------------------------------- ### Get Map Width (GXMapColumns) Source: https://github.com/boxgaming/gx/wiki/Methods Returns the width of the map, specified in tile columns. ```gx GXMapColumns() ``` -------------------------------- ### Create Entity with Sub Version and UID (VB) Source: https://github.com/boxgaming/gx/wiki/GXEntityCreate Creates a new game entity using the sub version of GXEntityCreate, requiring a unique string identifier (UID). This UID can be used to look up the entity's ID later using the GX function. Includes example logic for moving the entity and animating it based on key presses. ```vb '$INCLUDE: 'gx.bi' CONST SEQ_IDLE = 1 CONST SEQ_WALK_RIGHT = 2 CONST SEQ_WALK_LEFT = 3 GXSceneCreate 320, 200 DIM SHARED warhog AS LONG warhog = GXEntityCreate("img/warhog.png", 16, 16, 5) SUB GXOnGameEvent (e AS GXEvent) SELECT CASE e.event CASE GXEVENT_UPDATE: IF GXKeyDown(GXKEY_RIGHT) THEN GXEntityVX GX("warhog"), 2 GXEntityAnimate GX("warhog"), SEQ_WALK_RIGHT, 10 END IF END SELECT END SUB '$INCLUDE: 'gx.bm' ``` -------------------------------- ### Move Scene Left and Down with GXSceneMove Source: https://github.com/boxgaming/gx/wiki/GXSceneMove This example demonstrates how to move the scene 3 pixels to the left and 5 pixels down using the GXSceneMove function. Negative dx values move left, and positive dy values move down. ```vb GXSceneMove -3, 5 ``` -------------------------------- ### Get and Set GXSceneEmbedded Status (VB) Source: https://github.com/boxgaming/gx/wiki/GXSceneEmbedded This code snippet demonstrates how to retrieve the current embedded status of a scene and set it to true if it's not already embedded. This is useful when managing the game loop externally. ```vb IF NOT GXSceneEmbedded THEN GXSceneEmbedded GX_TRUE END IF ``` -------------------------------- ### Wait for 180 frames before exiting game after ESC press Source: https://github.com/boxgaming/gx/wiki/GXFrame This example demonstrates how to use GXFrame to implement a delay. It captures the frame when the ESC key is pressed and then checks if the current frame minus the captured frame exceeds 180 before stopping the scene. ```vb '$INCLUDE: 'gx.bi' DIM SHARED escPressed AS _UNSIGNED LONG GXSceneCreate 320, 200 GXSceneStart SUB GXOnGameEvent (e AS GXEvent) SELECT CASE e.event CASE GXEVENT_UPDATE IF GXKeyDown(GXKEY_ESC) THEN escPressed = GXFrame IF escPressed AND GXFrame - escPressed > 180 THEN GXSceneStop END SELECT END SUB '$INCLUDE: 'gx.bm' ``` -------------------------------- ### Stop Game Loop on ESC Press (GX) Source: https://github.com/boxgaming/gx/wiki/GXSceneStop Demonstrates stopping the GX game loop when the ESC key is pressed. This involves creating a scene, starting the game loop, and handling the GXEVENT_UPDATE event to check for key presses. ```vb '$INCLUDE: 'gx.bi' GXSceneCreate 320, 200 GXSceneStart PRINT "Game Over" SUB GXOnGameEvent (e AS GXEvent) SELECT CASE e.event CASE GXEVENT_UPDATE IF GXKeyDown(GXKEY_ESC) THEN GXSceneStop END SELECT END SUB '$INCLUDE: 'gx.bm' ``` -------------------------------- ### Get Entity Y Position (Visual Basic) Source: https://github.com/boxgaming/gx/wiki/GXEntityY Retrieves the vertical (y) position of a specified entity using its entity ID. The entity ID can be obtained from GXEntityCreate or GX. ```vb y% = GXEntityY(warhog) ``` -------------------------------- ### Get and Set Entity Vertical Velocity (VB) Source: https://github.com/boxgaming/gx/wiki/GXEntityVY Demonstrates how to retrieve the current vertical velocity (vy) of an entity and then increase it by 10 pixels per second using the GXEntityVY function. The entity is identified by 'warhog'. ```vb vy% = GXEntityVY(warhog) GXEntityVY warhog, vy% + 10 ``` -------------------------------- ### Stop Animation on Escape Key - VB Source: https://github.com/boxgaming/gx/wiki/GXEntityAnimateStop This example demonstrates how to stop an entity's animation sequence when the Escape key is pressed. It uses GXEntityAnimateStop to halt the animation and relies on GXKeyDown and GXOnGameEvent for input handling. The entity's ID is managed through GXEntityCreate. ```vb '$INCLUDE: 'gx.bi' CONST SEQ_IDLE = 1 CONST SEQ_WALK_RIGHT = 2 CONST SEQ_WALK_LEFT = 3 CONST SEQ_FIST_PUMP = 4 GXSceneCreate 320, 200 DIM SHARED warhog AS LONG warhog = GXEntityCreate("img/warhog.png", 16, 16, 5) GXEntityAnimateMode warhog, GXANIMATE_SINGLE GXEntityAnimate warhog, SEQ_FIST_PUMP, 10 GXSceneStart SUB GXOnGameEvent (e as GXEvent) SELECT CASE e.event CASE GXEVENT_UPDATE: IF GXKeyDown(GXKEY_ESC) THEN GXEntityAnimateStop warhog END IF END SELECT END SUB '$INCLUDE: 'gx.bm' ``` -------------------------------- ### Get and Set Horizontal Velocity (GXEntityVX) Source: https://github.com/boxgaming/gx/wiki/GXEntityVX Retrieves or modifies the horizontal velocity (vx) of an entity. The velocity is measured in pixels per second. A positive value moves right, a negative value moves left. It takes the entity ID and optionally the new velocity as parameters. ```vb vx% = GXEntityVX(warhog) GXEntityVX warhog, vx% + 10 ``` -------------------------------- ### Build and Run GX2Web Converter Source: https://github.com/boxgaming/gx/wiki/Publish-to-Web Commands to build the GX tools and run the gx2web converter to transform QB64 games into web assets. The output is placed in the dist directory. ```shell cd gx/tools ./build.sh ./gx2web ../samples/overworld/overworld.bas ``` -------------------------------- ### GX Game Initialization and Player Control (VB) Source: https://github.com/boxgaming/gx/wiki/Tutorial Initializes the GX game environment, loads a map, creates a player entity, and handles player movement based on keyboard input. It requires the gx.bi and gx.bm include files. ```vb '$Include: '../../gx/gx.bi' Const RIGHT = 1 Const LEFT = 2 Const DOWN = 3 Const UP = 4 GXSceneCreate 320, 180 GXSceneScale 2 GXMapLoad "../../samples/overworld/map/overworld.gxm" Dim Shared player As Long player = GXEntityCreate("../../samples/overworld/img/character.png", 16, 20, 4) GXEntityPos player, 150, 80 GXEntityFrameSet player, 3, 1 GXSceneFollowEntity player, GXSCENE_FOLLOW_ENTITY_CENTER GXSceneConstrain GXSCENE_CONSTRAIN_TO_MAP GXSceneStart Sub GXOnGameEvent (e As GXEvent) Select Case e.event Case GXEVENT_UPDATE: If GXKeyDown(GXKEY_ESC) Then GXSceneStop HandlePlayerControls End Select End Sub Sub HandlePlayerControls If GXKeyDown(GXKEY_DOWN) Then GXEntityVX player, 0 GXEntityVY player, 40 GXEntityAnimate player, DOWN, 10 ElseIf GXKeyDown(GXKEY_UP) Then GXEntityVX player, 0 GXEntityVY player, -40 GXEntityAnimate player, UP, 10 ElseIf GXKeyDown(GXKEY_RIGHT) Then GXEntityVX player, 40 GXEntityVY player, 0 GXEntityAnimate player, RIGHT, 10 ElseIf GXKeyDown(GXKEY_LEFT) Then GXEntityVX player, -40 GXEntityVY player, 0 GXEntityAnimate player, LEFT, 10 Else GXEntityVX player, 0 GXEntityVY player, 0 GXEntityAnimateStop player End If End Sub '$Include: '../../gx/gx.bm' ``` -------------------------------- ### Run GX Build Script (Windows) Source: https://github.com/boxgaming/gx/wiki/Getting-Started Executes the build script on Windows to compile the GX engine tools. Assumes the QB64_HOME environment variable has been set. ```batch > build.bat ``` -------------------------------- ### Testing Web Version with Local Server Source: https://github.com/boxgaming/gx/wiki/Publish-to-Web Instructions on how to test the converted web version of the game using the provided webserver. It specifies the command to run the server and the URL to access the game in a browser. ```shell tools/webserver.exe http://localhost:8080/dist/overworld/index.html ``` -------------------------------- ### Run GX Build Script (MacOS/Linux) Source: https://github.com/boxgaming/gx/wiki/Getting-Started Executes the build script on MacOS and Linux to compile the GX engine tools. Requires the QB64_HOME environment variable to be set. ```shell > /bin/sh build.sh ``` -------------------------------- ### Define Animation Constants and Create Scene (Visual Basic) Source: https://github.com/boxgaming/gx/wiki/Tutorial Defines constants for character animation directions and initializes the game scene with specified dimensions and scaling. Requires the gx.bi include file. ```vb '$Include: '../../gx/gx.bi' Const RIGHT = 1 Const LEFT = 2 Const DOWN = 3 Const UP = 4 GXSceneCreate 320, 180 GXSceneScale 2 ... ``` -------------------------------- ### Include GX Engine Files Source: https://github.com/boxgaming/gx/wiki/Tutorial Includes the core GX engine interface and backend modules. These are essential for accessing all GX functionalities. ```vb '$Include: '../../gx/gx.bi' '$Include: '../../gx/gx.bm' ``` -------------------------------- ### Configure Scene and Entity Display Source: https://github.com/boxgaming/gx/wiki/Tutorial Sets the scene scale, positions the player entity, and sets its animation frame. Also includes the necessary GX engine includes and event handler. ```vb '$Include: '../../gx/gx.bi' GXSceneCreate 320, 180 GXSceneScale 2 Dim Shared player As Long player = GXEntityCreate("../../samples/overworld/img/character.png", 16, 20, 4) GXEntityPos player, 150, 80 GXEntityFrameSet player, 3, 1 GXSceneStart Sub GXOnGameEvent (e As GXEvent) End Sub '$Include: '../../gx/gx.bm' ``` -------------------------------- ### Load a Tile-Based Map (Visual Basic) Source: https://github.com/boxgaming/gx/wiki/Tutorial Loads a tile-based map into the game scene using the GXMapLoad function. Also includes code to create and position the player entity. ```vb '... GXSceneCreate 320, 180 GXSceneScale 2 GXMapLoad "../../samples/overworld/map/overworld.gxm" Dim Shared player As Long player = GXEntityCreate("../../samples/overworld/img/character.png", 16, 20, 4) GXEntityPos player, 150, 80 GXEntityFrameSet player, 3, 1 ... ``` -------------------------------- ### Enable Fullscreen Mode Source: https://github.com/boxgaming/gx/wiki/Tutorial Replaces the scene scaling with a command to enable fullscreen mode for the game. Requires GX_TRUE constant. ```vb GXFullScreen GX_TRUE ``` -------------------------------- ### Control Player Animation Based on Input (Visual Basic) Source: https://github.com/boxgaming/gx/wiki/Tutorial Handles player input to control character movement and animation. Uses GXEntityVX, GXEntityVY, GXEntityAnimate, and GXEntityAnimateStop to manage velocity and animation sequences. Requires the gx.bm include file. ```vb 'Sub HandlePlayerControls If GXKeyDown(GXKEY_DOWN) Then GXEntityVX player, 0 GXEntityVY player, 40 GXEntityAnimate player, DOWN, 10 ElseIf GXKeyDown(GXKEY_UP) Then GXEntityVX player, 0 GXEntityVY player, -40 GXEntityAnimate player, UP, 10 ElseIf GXKeyDown(GXKEY_RIGHT) Then GXEntityVX player, 40 GXEntityVY player, 0 GXEntityAnimate player, RIGHT, 10 ElseIf GXKeyDown(GXKEY_LEFT) Then GXEntityVX player, -40 GXEntityVY player, 0 GXEntityAnimate player, LEFT, 10 Else GXEntityVX player, 0 GXEntityVY player, 0 GXEntityAnimateStop player End If End Sub '$Include: '../../gx/gx.bm' ``` -------------------------------- ### Scene Management API Source: https://github.com/boxgaming/gx/wiki/Methods Functions for creating, configuring, and controlling game scenes. ```APIDOC ## GXSceneCreate ### Description Creates a new scene with the specified pixel width and height. ### Method (Not specified, assumed to be a function call) ### Endpoint N/A ### Parameters * **width** (number) - Required - The pixel width of the scene. * **height** (number) - Required - The pixel height of the scene. ### Request Example ``` GXSceneCreate(800, 600) ``` ### Response (Not specified) ``` ```APIDOC ## GXSceneWindowSize ### Description Scales the scene to the specified window size. ### Method (Not specified, assumed to be a function call) ### Endpoint N/A ### Parameters * **width** (number) - Required - The target window width. * **height** (number) - Required - The target window height. ### Request Example ``` GXSceneWindowSize(1024, 768) ``` ### Response (Not specified) ``` ```APIDOC ## GXSceneScale ### Description Scales the scene by the specified scale factor. ### Method (Not specified, assumed to be a function call) ### Endpoint N/A ### Parameters * **scale** (number) - Required - The scale factor to apply to the scene. ### Request Example ``` GXSceneScale(1.5) ``` ### Response (Not specified) ``` ```APIDOC ## GXSceneResize ### Description Resize the scene with the specified pixel width and height. ### Method (Not specified, assumed to be a function call) ### Endpoint N/A ### Parameters * **width** (number) - Required - The new pixel width of the scene. * **height** (number) - Required - The new pixel height of the scene. ### Request Example ``` GXSceneResize(640, 480) ``` ### Response (Not specified) ``` ```APIDOC ## GXSceneDraw ### Description Draw the scene. This method is called automatically when GX is managing the event/game loop. Call this method for each page draw event when the event/game loop is being handled externally. ### Method (Not specified, assumed to be a function call) ### Endpoint N/A ### Parameters (None) ### Request Example ``` GXSceneDraw() ``` ### Response (Not specified) ``` ```APIDOC ## GXSceneMove ### Description Moves the scene position by the number of pixels specified by the dx and dy values. ### Method (Not specified, assumed to be a function call) ### Endpoint N/A ### Parameters * **dx** (number) - Required - The number of pixels to move horizontally. * **dy** (number) - Required - The number of pixels to move vertically. ### Request Example ``` GXSceneMove(10, -5) ``` ### Response (Not specified) ``` ```APIDOC ## GXScenePos ### Description Positions the scene at the specified x and y coordinates. The default position for a scene is (0,0). Negative x and y values are valid. ### Method (Not specified, assumed to be a function call) ### Endpoint N/A ### Parameters * **x** (number) - Required - The target x-coordinate. * **y** (number) - Required - The target y-coordinate. ### Request Example ``` GXScenePos(50, 100) ``` ### Response (Not specified) ``` ```APIDOC ## GXSceneX ### Description Returns the scene's current x position. ### Method (Not specified, assumed to be a function call) ### Endpoint N/A ### Parameters (None) ### Request Example ``` local currentX = GXSceneX() ``` ### Response * **x_position** (number) - The current x-coordinate of the scene. ``` ```APIDOC ## GXSceneY ### Description Returns the scene's current y position. ### Method (Not specified, assumed to be a function call) ### Endpoint N/A ### Parameters (None) ### Request Example ``` local currentY = GXSceneY() ``` ### Response * **y_position** (number) - The current y-coordinate of the scene. ``` ```APIDOC ## GXSceneWidth ### Description Returns the scene width. ### Method (Not specified, assumed to be a function call) ### Endpoint N/A ### Parameters (None) ### Request Example ``` local sceneWidth = GXSceneWidth() ``` ### Response * **width** (number) - The current width of the scene. ``` ```APIDOC ## GXSceneHeight ### Description Returns the scene height. ### Method (Not specified, assumed to be a function call) ### Endpoint N/A ### Parameters (None) ### Request Example ``` local sceneHeight = GXSceneHeight() ``` ### Response * **height** (number) - The current height of the scene. ``` ```APIDOC ## GXSceneColumns ### Description Returns the number of tile columns that can be displayed within the scene. This value will be zero unless a tiled map has been created or loaded. ### Method (Not specified, assumed to be a function call) ### Endpoint N/A ### Parameters (None) ### Request Example ``` local columns = GXSceneColumns() ``` ### Response * **columns** (number) - The number of tile columns. ``` ```APIDOC ## GXSceneRows ### Description Returns the number of tile rows that can be displayed within the scene. This value will be zero unless a tiled map has been created or loaded. ### Method (Not specified, assumed to be a function call) ### Endpoint N/A ### Parameters (None) ### Request Example ``` local rows = GXSceneRows() ``` ### Response * **rows** (number) - The number of tile rows. ``` ```APIDOC ## GXSceneStart ### Description Start the game loop. This method will not return control to the calling program until the game loop is interrupted with the GXSceneStop method. Game events will be sent to the GXOnGameEvent method during the game loop execution. ### Method (Not specified, assumed to be a function call) ### Endpoint N/A ### Parameters (None) ### Request Example ``` GXSceneStart() ``` ### Response (Not specified. Control returns upon GXSceneStop.) ``` ```APIDOC ## GXSceneStop ### Description Stop the game loop. This method will cause the game loop to end and return control to the calling program. ### Method (Not specified, assumed to be a function call) ### Endpoint N/A ### Parameters (None) ### Request Example ``` GXSceneStop() ``` ### Response (Not specified. Returns control to the calling program.) ``` -------------------------------- ### Create Player Entity Source: https://github.com/boxgaming/gx/wiki/Tutorial Creates a game entity using a spritesheet asset. It defines the entity's image, dimensions, and animation frames. ```vb '$Include: '../../gx/gx.bi' GXSceneCreate 320, 180 Dim Shared player As Long player = GXEntityCreate("../../samples/overworld/img/character.png", 16, 20, 4) Sub GXOnGameEvent (e As GXEvent) End Sub '$Include: '../../gx/gx.bm' ``` -------------------------------- ### Center Scene on Player Entity (Visual Basic) Source: https://github.com/boxgaming/gx/wiki/Tutorial Configures the game scene to follow a specified entity, centering the view on it. This allows the player to explore larger maps without going off-screen. ```vb '... Dim Shared player As Long player = GXEntityCreate("../../samples/overworld/img/character.png", 16, 20, 4) GXEntityPos player, 150, 80 GXEntityFrameSet player, 3, 1 GXSceneFollowEntity player, GXSCENE_FOLLOW_ENTITY_CENTER GXSceneStart ... ``` -------------------------------- ### Define GX Game Event Handler Source: https://github.com/boxgaming/gx/wiki/Tutorial Sets up the main game event handler subroutine, which the GX engine calls for all game-related events. This is a fundamental part of the game loop. ```vb '$Include: '../../gx/gx.bi' Sub GXOnGameEvent (e As GXEvent) End Sub '$Include: '../../gx/gx.bm' ``` -------------------------------- ### Implement Player Movement with Arrow Keys in GX Source: https://github.com/boxgaming/gx/wiki/Tutorial This code demonstrates how to handle player input using arrow keys to control character movement (velocity) within the GX game engine. It checks for key presses and updates the entity's X and Y velocities accordingly. Dependencies include the GX library and the GXOnGameEvent method. ```vb Sub GXOnGameEvent (e As GXEvent) Select Case e.event Case GXEVENT_UPDATE: If GXKeyDown(GXKEY_ESC) Then GXSceneStop HandlePlayerControls End Select End Sub Sub HandlePlayerControls If GXKeyDown(GXKEY_DOWN) Then GXEntityVX player, 0 GXEntityVY player, 25 ElseIf GXKeyDown(GXKEY_UP) Then GXEntityVX player, 0 GXEntityVY player, -25 ElseIf GXKeyDown(GXKEY_RIGHT) Then GXEntityVX player, 25 GXEntityVY player, 0 ElseIf GXKeyDown(GXKEY_LEFT) Then GXEntityVX player, -25 GXEntityVY player, 0 Else GXEntityVX player, 0 GXEntityVY player, 0 End If End Sub '$Include: '../../gx/gx.bm' ``` -------------------------------- ### Stop Game Scene Immediately in GX Source: https://github.com/boxgaming/gx/wiki/Tutorial This code snippet demonstrates how to immediately stop the game scene and exit the application by calling the System method after GXSceneStop. It's used to ensure a clean exit. ```vb GXSceneStart System ``` -------------------------------- ### Center Scene on Entity (Visual Basic) Source: https://github.com/boxgaming/gx/wiki/GXSceneFollowEntity Centers the game scene on a specified entity. Requires a valid entity ID and a follow mode. Initializes the scene and creates an entity before applying the follow behavior. ```vb GXSceneCreate 320, 180 DIM SHARED warhog AS LONG warhog = GXEntityCreate("img/warhog.png", 16, 16, 5) GXSceneFollowEntity warhog, GXSCENE_FOLLOW_ENTITY_CENTER ``` -------------------------------- ### CSS Styling for GX Game Interface Source: https://github.com/boxgaming/gx/blob/main/tools/web/index.html Defines the visual appearance and layout of the GX game interface using CSS. Includes font definitions, background styles, element positioning, and hover effects for interactive elements. ```css @font-face { font-family: dosvga; src: url(qbjs.woff2); } body { background-color: #333; font-family: dosvga, Arial, Helvetica, sans-serif; } #gx-container { text-align: center; } #gx-footer { margin: 0 auto; background-color: #666; display: flex; justify-content: space-between; width: 960px; } #gx-link, #gx-fullscreen { margin: 1px; } #gx-canvas { border: 1px solid #222; background-color: #000; } #gx-load-screen { display: block; text-align: center; margin: auto; width: 960px; height: 600px; font-size: 24px; color: #ccc; border: 1px solid #000; text-decoration: none; background-position: center center; background-image: url('play.png'); background-repeat: no-repeat; background-color: #444; } #gx-load-screen:hover { background-color: #555; } ``` -------------------------------- ### Set Entity Animation Frame (Visual Basic) Source: https://github.com/boxgaming/gx/wiki/GXEntityFrameSet Demonstrates how to create an entity and set its animation frame using GXEntityFrameSet. It defines animation sequence constants and uses GXEntityCreate to initialize an entity. ```vb CONST WALK = 1 CONST CHARGE = 2 CONST IDLE = 3 DIM SHARED warhog AS LONG warhog = GXEntityCreate("img/warhog.png", 16, 16, 5) GXEntityFrameSet warhog, WALK, 3 ``` -------------------------------- ### Entity Manipulation API Source: https://github.com/boxgaming/gx/wiki/Methods Functions for creating, animating, and controlling game entities. ```APIDOC ## GXEntityAnimate ### Description Animates a specified entity. ### Method (Not specified, assumed to be a function call) ### Endpoint N/A ### Parameters * **entity** (object/id) - Required - The entity to animate. ### Request Example ``` GXEntityAnimate(playerEntity) ``` ### Response (Not specified) ``` ```APIDOC ## GXEntityAnimateStop ### Description Stops animation of the current animation sequence. ### Method (Not specified, assumed to be a function call) ### Endpoint N/A ### Parameters * **entity** (object/id) - Required - The entity whose animation should stop. ### Request Example ``` GXEntityAnimateStop(enemyEntity) ``` ### Response (Not specified) ``` ```APIDOC ## GXEntityAnimateMode ### Description Gets or sets the animation mode of a specified entity. ### Method (Not specified, assumed to be a function call) ### Endpoint N/A ### Parameters * **entity** (object/id) - Required - The entity to modify. * **mode** (string) - Optional - The animation mode to set (e.g., 'loop', 'once'). If omitted, returns the current mode. ### Request Example ``` -- Set animation mode GXEntityAnimateMode(character, 'loop') -- Get animation mode local currentMode = GXEntityAnimateMode(character) ``` ### Response * **mode** (string) - The current animation mode of the entity (if getting mode). ``` ```APIDOC ## GXScreenEntityCreate ### Description Creates a new game entity. In GX an entity is an object that can be placed into and interact with the game world. An entity has an x and y position, a height and width, as well as basic physics properties like velocity. An entity is created from a spritesheet image. Each row of the spritesheet should contain a separate animation sequence. ### Method (Not specified, assumed to be a function call) ### Endpoint N/A ### Parameters * **spritesheet** (string) - Required - The path or identifier for the spritesheet image. * **x** (number) - Required - The initial x-coordinate of the entity. * **y** (number) - Required - The initial y-coordinate of the entity. * **width** (number) - Required - The width of the entity. * **height** (number) - Required - The height of the entity. ### Request Example ``` local player = GXScreenEntityCreate('player_sprites.png', 100, 150, 32, 32) ``` ### Response * **entity** (object/id) - A reference to the newly created entity. ``` ```APIDOC ## GXEntityMove ### Description Move the specified entity relative to its current position. ### Method (Not specified, assumed to be a function call) ### Endpoint N/A ### Parameters * **entity** (object/id) - Required - The entity to move. * **dx** (number) - Required - The horizontal distance to move. * **dy** (number) - Required - The vertical distance to move. ### Request Example ``` GXEntityMove(player, 5, 0) ``` ### Response (Not specified) ``` ```APIDOC ## GXEntityPos ### Description Position the entity at the specified x and y pixel coordinates. ### Method (Not specified, assumed to be a function call) ### Endpoint N/A ### Parameters * **entity** (object/id) - Required - The entity to position. * **x** (number) - Required - The target x-coordinate. * **y** (number) - Required - The target y-coordinate. ### Request Example ``` GXEntityPos(enemy, 200, 250) ``` ### Response (Not specified) ``` ```APIDOC ## GXEntityVX ### Description Gets or sets the horizontal velocity (vx) of the specified entity. The value of the horizontal velocity (vx) is specified as the number of pixels per second. A positive value indicates movement to the right. A negative value indicates movement to the left. ### Method (Not specified, assumed to be a function call) ### Endpoint N/A ### Parameters * **entity** (object/id) - Required - The entity whose velocity to get or set. * **vx** (number) - Optional - The horizontal velocity to set. If omitted, returns the current horizontal velocity. ### Request Example ``` -- Set horizontal velocity GXEntityVX(player, 100) -- Get horizontal velocity local currentVx = GXEntityVX(player) ``` ### Response * **vx** (number) - The current horizontal velocity of the entity (if getting velocity). ``` ```APIDOC ## GXEntityVY ### Description Gets or sets the vertical velocity (vx) of the specified entity. The value of the vertical velocity (vx) is specified as the number of pixels per second. A positive value indicates downward movement. A negative value indicates upward movement. ### Method (Not specified, assumed to be a function call) ### Endpoint N/A ### Parameters * **entity** (object/id) - Required - The entity whose velocity to get or set. * **vy** (number) - Optional - The vertical velocity to set. If omitted, returns the current vertical velocity. ### Request Example ``` -- Set vertical velocity GXEntityVY(player, -50) -- Get vertical velocity local currentVy = GXEntityVY(player) ``` ### Response * **vy** (number) - The current vertical velocity of the entity (if getting velocity). ``` ```APIDOC ## GXEntityX ### Description Returns the horizontal (x) position of the specified entity. ### Method (Not specified, assumed to be a function call) ### Endpoint N/A ### Parameters * **entity** (object/id) - Required - The entity whose position to get. ### Request Example ``` local entityX = GXEntityX(player) ``` ### Response * **x_position** (number) - The current x-coordinate of the entity. ``` ```APIDOC ## GXEntityY ### Description Returns the vertical (y) position of the specified entity. ### Method (Not specified, assumed to be a function call) ### Endpoint N/A ### Parameters * **entity** (object/id) - Required - The entity whose position to get. ### Request Example ``` local entityY = GXEntityY(player) ``` ### Response * **y_position** (number) - The current y-coordinate of the entity. ``` ```APIDOC ## GXEntityWidth ### Description Returns the width of the specified entity. ### Method (Not specified, assumed to be a function call) ### Endpoint N/A ### Parameters * **entity** (object/id) - Required - The entity whose width to get. ### Request Example ``` local entityWidth = GXEntityWidth(player) ``` ### Response * **width** (number) - The current width of the entity. ``` ```APIDOC ## GXEntityHeight ### Description Returns the height of the specified entity. ### Method (Not specified, assumed to be a function call) ### Endpoint N/A ### Parameters * **entity** (object/id) - Required - The entity whose height to get. ### Request Example ``` local entityHeight = GXEntityHeight(player) ``` ### Response * **height** (number) - The current height of the entity. ``` ```APIDOC ## GXEntityFrameNext ### Description Advance to the next animation frame in the current animation sequence for a specified entity. ### Method (Not specified, assumed to be a function call) ### Endpoint N/A ### Parameters * **entity** (object/id) - Required - The entity to advance the frame for. ### Request Example ``` GXEntityFrameNext(player) ``` ### Response (Not specified) ``` ```APIDOC ## GXEntityFrameSet ### Description Set the current animation frame for a specified entity. ### Method (Not specified, assumed to be a function call) ### Endpoint N/A ### Parameters * **entity** (object/id) - Required - The entity to set the frame for. * **frameIndex** (number) - Required - The index of the frame to set. ### Request Example ``` GXEntityFrameSet(player, 5) ``` ### Response (Not specified) ``` ```APIDOC ## GXEntityApplyGravity ### Description Gets or sets the "apply gravity" mode of a specified entity. ### Method (Not specified, assumed to be a function call) ### Endpoint N/A ### Parameters * **entity** (object/id) - Required - The entity to modify. * **applyGravity** (boolean) - Optional - Set to true to apply gravity, false to disable. If omitted, returns the current gravity status. ### Request Example ``` -- Enable gravity GXEntityApplyGravity(player, true) -- Check if gravity is applied local isGravityOn = GXEntityApplyGravity(player) ``` ### Response * **applyGravity** (boolean) - The current gravity status of the entity (if getting status). ``` ```APIDOC ## GXEntityCollisionOffset ### Description Sets the collision offset for a specified entity. By default the collision rectangle is set to the border of the entity as defined by its height and width. A smaller or larger area can be defined for collision detection with this method. ### Method (Not specified, assumed to be a function call) ### Endpoint N/A ### Parameters * **entity** (object/id) - Required - The entity to set the collision offset for. * **left** (number) - Required - The left offset. * **top** (number) - Required - The top offset. * **right** (number) - Required - The right offset. * **bottom** (number) - Required - The bottom offset. ### Request Example ``` GXEntityCollisionOffset(player, 2, 2, 2, 2) ``` ### Response (Not specified) ``` -------------------------------- ### Add Backgrounds to Scene (Visual Basic) Source: https://github.com/boxgaming/gx/wiki/GXBackgroundAdd Demonstrates adding two background images to a scene using GXBackgroundAdd. The first image ('mountain.png') is stretched to fit the scene, while the second ('trees.png') is set to scroll with the map position. ```vb GXSceneCreate 320, 200 GXBackgroundAdd "mountain.png", GXBG_STRETCH GXBackgroundAdd "trees.png", GXBG_SCROLL ```