Complete command and function reference for GameBASIC.
LET IMG = "MY_IMAGE").Use the Base64 Data panel to manage large Base64 strings separately from your program code. Each entry has a name and a Base64 string.
LET IMG = "MY_IMAGE").// Example usage LET SPRITE = "MY_SPRITE" BANKLOADSPRITE(1, SPRITE, 16, 16) // 'MY_SPRITE' is a Base64 entry managed in the panel
Returns the Base64 string for the entry named name from the Base64 Data panel.
LET V = GETBASE64("TheId") to assign the Base64 string to a variable.// Example usage
LET SPRITE = GETBASE64("MY_SPRITE")
BANKLOADSPRITE(1, SPRITE, 16, 16)
// 'MY_SPRITE' is a Base64 entry managed in the panelSingle-line comment. Ignored during execution.
REM This is a comment // Double-slash also works
name: Variable name | expr: Any expression
Assign a value to a variable.
Scope rules:
X = 100 // Global variable FUNC TEST() X = X + 10 // Modifies global X (now 110) LET Y = 20 // Creates local Y END TEST() PRINT(X) // 110 PRINT(Y) // Error: Y is local to TEST
name: Array name | size: Maximum index (0-indexed)
Create a one-dimensional array.
Scope rules:
DIM GLOBAL(10) // Global array FUNC TEST() DIM LOCAL(5) // Local to TEST GLOBAL(0) = 100 // Can access global LOCAL(0) = 50 // Local only END GLOBAL(0) = 1 // OK LOCAL(0) = 1 // Error: LOCAL not defined here
Define data entries. Use READ to retrieve them sequentially.
DATA 10, 20, 30, 40 READ A, B PRINT(A, B) // Outputs: 10 20
Read next values from DATA into variables.
DATA 100, 200 READ X, Y PRINT(X, Y)
id: Optional DATA label
Reset DATA pointer to start (or specific label).
DATA VALUES, 1, 2, 3 RESTORE VALUES READ A, B, C
Conditional block. ELSEIF and ELSE are optional.
// Multi-line form
IF X > 100 THEN
PRINT("HIGH")
ELSEIF X > 50 THEN
PRINT("MEDIUM")
ELSE
PRINT("LOW")
ENDIF
// Single-line form (no ENDIF required when THEN is followed by a single statement)
IF X == 2 THEN PRINT("HELLO")var: Loop variable | start, end: Range | step: Increment (default 1)
Counted loop. End with NEXT var.
FOR I = 0 TO 10 PRINT(I) NEXT FOR J = 10 TO 0 STEP -1 PRINT(J) NEXT
Loop while condition is true.
X = 0 WHILE X < 100 X = X + 1 ENDWHILE
Define a user function. Call with name(args) or FUNC name(args).
Variable scope in functions:
SCORE = 0 // Global FUNC ADDSCORE(POINTS) SCORE = SCORE + POINTS // Modifies global LET BONUS = POINTS * 2 // Local only END ADDSCORE(10) PRINT(SCORE) // 10
Return from function with optional value.
Stop program execution immediately.
value: Any expression or string
Print values to screen output (wraps long text). Multiple values separated by spaces.
PRINT("Score:", 1000)
PRINT("Multiple values", "with", "spaces")x, y: Pixel coordinates | text: String to draw | color: Optional CSS color
Draw text at a specific position.
TEXT(10, 20, "Hello World", "#ffff00") TEXT(50, 100, "Default color")
text: String to draw | y: Optional Y position (default: centered vertically) | color: Optional CSS color
Draw text centered horizontally.
TEXTCENTER("TITLE")
TEXTCENTER("Score: 1000", 50, "#00ff00")color: CSS color string
Set the default text and drawing color.
SETTEXTCOLOR("#ffcc00")
PRINT("This is golden")color: CSS color string, or null/empty to disable
Add an outline/stroke around text for better visibility.
SETTEXTCOLOR("#ffffff")
SETTEXTOUTLINE("#000000")
TEXT(10, 10, "Outlined text")x, y: Scale factors (e.g., 0.5, 1, 2)
Set text scaling for width and height.
SETTEXTSCALE(0.5, 1) // 4x8 text SETTEXTSCALE(1, 2) // 8x16 text
x: Width scale factor
Set text width scale only.
SETTEXTSCALEX(0.5)
PRINT("Half-width text")y: Height scale factor
Set text height scale only.
SETTEXTSCALEY(1.5) TEXT(10, 10, "Taller text")
Alias for SETTEXTCOLOR().
Clear all draw operations and reset display.
CLEARSCREEN()
PRINT("Fresh start")Clear text output lines only.
Render all queued drawing operations to the screen. Typically called once per frame.
FOR I = 1 TO 10
CLEARSCREEN()
PRINT("Frame", I)
FLIP()
WAIT(0.1)
NEXTcolor: CSS color string
Set background color for the screen (or active window).
SCREENBG("#1a1a2e")
FLIP()color: CSS color string
Set the border color outside the 320×200 canvas.
BORDER("#ff0000")fps: Frames per second (numeric)
Set target frame rate.
SETFPS(30) // 30 FPS WHILE 1 FLIP() ENDWHILE
mode: 1 = pixel-perfect, 0 = smooth
Set rendering mode for shapes. Default is 1.
PIXELMODE(1) FELLIPSE(160, 100, 50, 30)
Windows define rectangular drawing areas. All drawing within a window is clipped to its bounds.
id: Window identifier | x, y, w, h: Rectangle bounds | radius: Optional corner radius
Define a new window.
WINDOW("HUD", 0, 0, 320, 30)
WINDOW("GAME", 0, 30, 320, 170, 4)id: Window identifier
Activate a window for drawing.
USEWINDOW("HUD")
TEXT(5, 5, "Score: 1000")
USEWINDOW("GAME")
LINE(10, 10, 100, 100)Disable window clipping (draw to full screen).
Get active window bounds (x, y, width, height).
W = WINDOWW()
H = WINDOWH()
PRINT("Window size:", W, "x", H)x1, y1, x2, y2: Start and end points | color: Optional CSS color
Draw a line between two points.
LINE(10, 10, 100, 100, "#ff0000") LINE(50, 50, 200, 50)
x, y: Top-left corner | w, h: Width and height | color: Optional CSS color
Draw a rectangle outline.
RECT(10, 10, 100, 50, "#00ff00")
Draw a filled rectangle.
FRECT(50, 50, 50, 50, "#ffff00")
cx, cy: Center | rx, ry: Horizontal and vertical radii | color: Optional CSS color
Draw an ellipse outline.
ELLIPSE(160, 100, 80, 50, "#0088ff")
Draw a filled ellipse.
FELLIPSE(160, 100, 50, 30, "#ff00ff")
cx, cy: Center | r: Radius | startDeg, endDeg: Angles in degrees
Draw an arc outline.
ARC(160, 100, 50, 0, 180, "#ffaa00")
Draw a filled arc (pie slice).
x1, y1, x2, y2, ...: Polygon vertices
Draw a polygon outline.
POLY(100, 50, 150, 100, 50, 100, "#00aa00")
Draw a filled polygon.
name: Sprite identifier | w, h: Width and height | color: CSS color
Create a solid-color sprite.
SPRITE("PLAYER", 16, 16, "#ff0000")
SPRITE("ENEMY", 8, 8, "#00ff00")Create a sprite from an image URL.
SPRITE("HERO", "https://example.com/hero.png")name: Sprite identifier | x, y: Draw position
Draw sprite at the specified position.
DRAWSPRITE("PLAYER", 100, 100)Set sprite position (compatibility alias for DRAWSPRITE).
Get current sprite position (x or y).
X = SPRITEX("PLAYER")
Y = SPRITEY("PLAYER")frameIndex: Frame number (0-indexed)
Change the current frame of a sprite bank.
SETSPRITEFRAME("WALK", 0)
WAIT(0.1)
SETSPRITEFRAME("WALK", 1)name: Sprite identifier | bankId: Bank with sprite sheet | frameIndex: Starting frame
Create a sprite from a sprite bank.
scaleX, scaleY: Scale factors | rotationDeg: Rotation in degrees | flipX, flipY: Flip flags (0 or 1)
Transform a sprite.
SETSPRITETRANSFORM("PLAYER", 2, 2, 45, 0, 0)hotX, hotY: Offset from sprite origin
Set the sprite rotation/positioning origin point.
nameA, nameB: Sprite names | ax, ay, bx, by: Positions
Check AABB collision between two sprites. Returns 1 if colliding, 0 otherwise.
IF COLLIDES("PLAYER", PX, PY, "ENEMY", EX, EY) THEN
PRINT("HIT!")
ENDIFCheck if two rectangles overlap.
IF RECTHIT(10, 10, 50, 50, 40, 40, 50, 50) THEN
PRINT("Rectangles overlap")
ENDIFcx, cy, rx, ry: Ellipse center and radii | px, py: Point to test
Check if a point is inside an ellipse.
id: Bank identifier (number or string) | size: Number of bytes
Create a byte bank (Uint8Array).
BANKCREATE("BUFFER", 256000)
BANKCREATE(1, 1024)id: Bank identifier | index: Byte offset
Read a byte from bank (0-255). Returns 0 if out of bounds.
VALUE = BANKPEEK("BUFFER", 10)value: Byte to write (clamped to 0-255)
Write a byte to bank.
BANKPOKE("BUFFER", 10, 255)data: Hex string (space-separated) or BASE64: prefix
Load pre-formatted data into a bank.
BANKLOAD(1, "00 FF 1A 2B") BANKLOAD(2, "BASE64:AAECAwQ=")
Copy one bank to another.
Delete a bank and free its memory.
bankId: Bank identifier (requires 256,000 bytes for full screen)
Save the current screen to a bank (320×200 RGBA = 256,000 bytes).
BANKCREATE("SCREEN", 256000)
CLEARSCREEN()
LINE(0, 0, 319, 199, "#ffffff")
FLIP()
SCREENCAPTURE("SCREEN")Restore a full screen from a bank.
SCREENDRAW("SCREEN")flipH, flipV: 1 to flip horizontally/vertically, 0 for normal
Draw a captured screen as a scaled rectangle, optionally flipped.
SCREENDRAWRECT("SCREEN", 0, 0, 160, 100) // Half-size
SCREENDRAWRECT("SCREEN", 160, 0, 160, 100, 1) // Flipped horizontally
SCREENDRAWRECT("SCREEN", 0, 100, 160, 100, 0, 1) // Flipped verticallyprompt: Optional message to display | cursor: Single character to show (default "_") | maxLen: Optional maximum characters
Display a prompt and wait for text input. Returns the entered string.
NAME = INPUT("What is your name?")
AGE = INPUT("Age:", ">", 3)
PRINT("Hello,", NAME)code: Key code string (e.g., "Space", "ArrowLeft", "a")
Check if a key is currently pressed. Returns 1 if down, 0 if up.
IF KEYDOWN("ArrowUp") THEN Y = Y - 1 ENDIF
IF KEYDOWN("ArrowUp") THEN Y = Y - 1
IF KEYDOWN("Space") THEN PRINT("JUMP")Get the last key that was pressed (as a string).
KEY = LASTKEY() IF KEY = "Escape" THEN END
seconds: Duration to pause
Pause execution for a number of seconds (fractional).
PRINT("Starting...")
WAIT(1)
PRINT("Done!")Create a named tilemap grid with given columns and rows.
TILEMAP_CREATE("ROOM1", 20, 15)Set the tile value at coordinates (x,y) in the named map.
TILEMAP_SET("ROOM1", 3, 2, 5)Get the numeric tile value at (x,y).
t = TILEMAP_GET("ROOM1", 3, 2)
PRINT(t)Fill the entire map with a value.
TILEMAP_FILL("ROOM1", 0)Draw the tilemap using frames from a sprite bank loaded with BANKLOADSPRITE. Each tile value is taken as a frame index into the bank. Optional scale scales tiles on display.
// Assume bank 1 contains a tileset with frames sized 16x16
TILEMAP_DRAW("ROOM1", 0, 0, 1, 2) // draws ROOM1 at (0,0) scaled 2xReturn 1 if the tile at (x,y) equals value, otherwise 0. Coordinates are in tile units.
IF TILEMAP_COLLIDE("ROOM1", PX, PY, 2) THEN PRINT("Hit wall")Return 1 if any tile inside the rectangle (x,y,w,h) equals value, otherwise 0.
IF TILEMAP_COLLIDE_RECT("ROOM1", PX-1, PY-1, 3, 3, 5) THEN PRINT("Overlap tile 5")Pixel-aware collision: returns 1 if the tile under pixel (px,py) equals value. Optional tileSize (default 8) specifies tile width/height in pixels.
// Check pixel 8,8 using 8px tiles
IF TILEMAP_COLLIDE_PIXEL("ROOM1", 8, 8, 1, 8) THEN PRINT("Hit")Pixel-aware rectangle collision: returns 1 if any tile overlapped by the pixel rectangle equals value.
IF TILEMAP_COLLIDE_RECT_PIXEL("ROOM1", 8, 8, 8, 8, 1) THEN PRINT("Overlap")value: Number used to seed the RNG
Set a deterministic seed for RND(). If not called, RND uses the browser's RNG.
SEED(1234) A = RND() B = RND(10)
max: Upper limit (exclusive)
Generate a random float in the range [0, max). Default max=1.
X = RND(320) Y = RND(200) DICE = INT(RND(6)) + 1
Floor to integer (truncate decimal part).
A = INT(3.7) // Returns 3 B = INT(-2.5) // Returns -3
value: Number 0-255
Convert a byte value to a 2-character uppercase hex string.
R = 255 G = 0 B = 127 COLOR = "#" & HEX(R) & HEX(G) & HEX(B) // "#FF007F"
Trigonometric functions. Input in radians.
X = 160 + COS(ANGLE) * 50 Y = 100 + SIN(ANGLE) * 30 ANGLE = ANGLE + 0.05
Get the length of a string.
LEN = STRLEN("Hello") // Returns 5wave: 0=sine, 1=sawtooth, 2=square, 4=noise | note: MIDI note number (0=middle C) | seconds: Duration
Play a sound. For noise, the note parameter controls filter pitch.
SOUND(0, 0, 0.2) // Sine wave, middle C SOUND(2, 12, 0.1) // Square wave, one octave up SOUND(4, 5, 0.3) // White noise
bankId: Bank containing 1024 bytes (128 chars × 8 bytes per char)
Set a custom font from a bank.
Use the ampersand operator & to join strings:
MESSAGE = "Score: " & SCORE & " points" COLOR = "#" & HEX(R) & HEX(G) & HEX(B)