Make 2D Games with Tiniest2D
Exporting and Best Practices
Lesson 11 of 11 • 10 XP
Keep your place in this quest
Log in or sign up for free to subscribe, follow lesson progress, and access more learning content.
Exporting Your Game
- Click the Export icon in the top bar
- Choose a location and filename for your game
- The engine creates a standalone
.exewith your project embedded - Distribute this single file - no other files needed!
The exported game:
- Runs without the editor interface
- Contains all images, scenes, and code
- Is encrypted to protect your assets
Tips and Best Practices
Performance
- Keep image sizes reasonable (pixels, not high-res)
- Remove objects you no longer need with
removeObject() - Use layers to organize rendering order
Organization
- Give meaningful names to objects and images
- Use comments to document your code
- Group related variables together
Debugging
- Use
print()to output variable values - Print messages appear in the game window
- Check collision types if objects pass through walls
Common Issues
Objects not colliding:
- Check collision types (both objects need appropriate types)
- Make sure objects are added to the scene
- Verify the sprite has a collider enabled
Objects pass through walls:
- Walls should be
COLLISION_STATIC() - Moving objects should be
COLLISION_DYNAMIC() - Very fast objects might tunnel - reduce speed or increase collision bounds
Camera not following player:
- Update camera position in
onUpdate(), not juststart() - Remember camera position is the center of the view
Quick Reference Card
// Create assets
var img = Sprite(16, 16)
var scene = Scene()
var sfx = Audio()
var obj = Object("Name")
// Object manipulation
setX(obj, 100)
setY(obj, 100)
setSprite(obj, img)
setCollisionType(obj, COLLISION_DYNAMIC())
addObject(scene, obj)
// Sprite manipulation
fillSprite(img, 255, 0, 0, 255) // Fill with red
setPixel(img, 0, 5, 5, 0, 255, 0, 255) // Set pixel at (5,5) on frame 0
var color = getPixel(img, 0, 5, 5) // Get [r,g,b,a] at (5,5)
setAnimationFPS(img, 24) // Set animation speed
var fps = getAnimationFPS(img) // Get animation speed
// Physics (velocity + gravity)
setGravityY(scene, 300) // Set scene gravity
setVelocityX(obj, 100) // Move right
setVelocityY(obj, -200) // Jump up
// Animation control
setFrame(obj, 0) // Set to specific frame
var frame = getFrame(obj) // Get current frame
var count = getFrameCount(obj) // Total frames
// Scene control
setScene(scene)
resetScene(scene)
setBackgroundColor(scene, 135, 206, 235) // Sky blue
// Scene queries
var obj = getObjectAt(scene, mx, my) // Object at point
var hits = getObjectsInBox(scene, x, y, 32, 32) // Objects in area
var enemy = getObjectByName(scene, "enemy") // Find by name
var all = getAllObjects(scene) // Get all objects
var count = getObjectCount(scene) // Count objects
var coins = getObjectsBySprite(scene, coinSprite) // By sprite
var enemies = getObjectsByCollisionType(scene, COLLISION_DYNAMIC())
// Audio
var handle = playAudio(sfx)
if (isAudioPlaying(handle)) { }
stopAudio(handle)
// Camera (position = center of view)
setCameraX(scene, x)
setCameraY(scene, y)
setCameraZoom(scene, 3.0) // Shows 240 world units vertically
// Screen and coordinate conversion
var w = getScreenWidth()
var h = getScreenHeight()
var worldPos = screenToWorld(mouseX, mouseY) // [worldX, worldY]
var screenPos = worldToScreen(objX, objY) // [screenX, screenY]
// Window mode (only affects exported games)
setWindowMode(WINDOW_MAXIMIZED()) // Default
setWindowMode(WINDOW_FULLSCREEN()) // Borderless fullscreen
setWindowMode(WINDOW_WINDOWED()) // Regular window
// Keyboard input
if (isKeyPressed(KEY_SPACE())) { }
if (isKeyHeld(KEY_LEFT())) { }
// Mouse input
if (isMouseButtonPressed(MOUSE_LEFT())) { }
var mx = getMouseX()
var my = getMouseY()
// Random numbers and math
var r = random() // 0.0 to 1.0
var n = randomInt(1, 10) // 1 to 10
var x = clamp(14, 0, 10) // 10
var y = lerp(0, 100, 0.5) // 50
var snapped = round(15.7) // 16
var dir = sign(-8) // -1
var power = pow(2, 3) // 8
var angle = PI() / 2 // 1.5708... radians
var bob = sin(angle) // Trig uses radians
var deg = rad2deg(angle) // 90 degrees
// UI style stacks
uiPushElementColor(28, 40, 70, 220)
uiPushFontColor(255, 220, 120)
uiLabel("READY", 4, 4)
uiPopFontColor()
uiPopElementColor()
// Storage (save/load game data)
var data = [100, "Player", true]
save(getAppDataPath() + "/MyGame/save.dat", data)
var loaded = load(getAppDataPath() + "/MyGame/save.dat")
if (fileExists(getAppDataPath() + "/MyGame/save.dat")) { }
deleteFile(getAppDataPath() + "/MyGame/old.dat")
// Game control
quitGame() // Exit the game
// Game loop
func start() { }
func onUpdate(dt) { }
func onCollision(a, b) { }
func end() { }
Tiniest 2D Pixel Engine - Make games, not engines.