Skip to content

API Quick Reference

A cheat sheet of essential LITIENGINE API methods and patterns.

Game Lifecycle

Game.init(args); // Initialize engine
Game.start(); // Start game loop
Game.exit(); // Terminate game

Game.info().setName("My Game"); // Set game name
Game.info().setVersion("v1.0.0"); // Set version

Game Components

Game.loop() // Game loop (logic + rendering)
Game.graphics() // Render engine
Game.audio() // Sound engine
Game.physics() // Physics engine
Game.tweens() // Tween engine
Game.world() // World/environment manager
Game.window() // Game window
Game.screens() // Screen manager
Game.scripts() // Script engine manager
Game.config() // Configuration
Game.info() // Game metadata
Game.metrics() // Performance metrics
Game.time() // Game time utilities
Game.random() // Random number generator

World & Environment

Game.world().loadEnvironment("level1"); // Load by name
Game.world().loadEnvironment(new Environment(map)); // Load instance
Game.world().environment(); // Current environment
Game.world().camera(); // Current camera

Game.world().environment().get("entityName"); // Get entity by name
Game.world().environment().getByType(Creature.class); // Get by type
Game.world().environment().getByTag("enemy"); // Get by tag
Game.world().environment().add(entity); // Add entity
Game.world().environment().remove(entity); // Remove entity

Game Loop

Game.loop().attach(updateable); // Register for updates
Game.loop().detach(updateable); // Unregister
Game.loop().getDeltaTime(); // Ms since last tick
Game.loop().getTicks(); // Total ticks
Game.loop().getTickRate(); // Ticks per second
Game.loop().setTickRate(30); // Change tick rate
Game.loop().execute(60, () -> {...}); // Execute after 60 ticks

Input

Input.keyboard() // Keyboard access
Input.mouse() // Mouse access
Input.gamepads() // Gamepad manager

// Keyboard
Input.keyboard().onKeyPressed(KeyEvent.VK_SPACE, e -> {...});
Input.keyboard().onKeyReleased(KeyEvent.VK_SPACE, e -> {...});
Input.keyboard().isPressed(KeyEvent.VK_SPACE);

// Mouse
Input.mouse().getLocation(); // Current position
Input.mouse().isLeftMouseButtonDown();
Input.mouse().isRightMouseButtonDown();
Input.mouse().onClicked(e -> {...});
Input.mouse().onMoved(e -> {...});

// Gamepad (Input4j Panama FFM)
Gamepad gamepad = Input.gamepads().getCurrent();
Input.gamepads().onPressed(Gamepad.Xbox.A, value -> {...});
Input.gamepads().onAdded(pad -> System.out.println("Gamepad connected: " + pad.getName()));
Input.gamepads().onRemoved(pad -> System.out.println("Gamepad disconnected: " + pad.getName()));

Script Engine & Bindings

Game.scripts(); // Script engine manager
Game.scripts().get("patrol_ai"); // Query loaded script by ID
Game.scripts().getEntities("patrol_ai"); // Query all entities bound to script

Rendering

Game.graphics().renderText(g, "text", x, y);
Game.graphics().renderShape(g, shape);
Game.graphics().renderImage(g, image, x, y);
Game.graphics().setBaseRenderScale(3f);

Audio

Game.audio().playSound("sound.wav");
Game.audio().playSound("sound.wav", x, y); // At location
Game.audio().playMusic("music.ogg");
Game.audio().stopMusic();
Game.audio().setSoundVolume(0.5f);
Game.audio().setMusicVolume(0.8f);

Physics

Game.physics().move(entity, angle, pixels);
Game.physics().add(collisionEntity);
Game.physics().remove(collisionEntity);
Game.physics().raycast(start, end);

Resources

Resources.load("game.litidata"); // Load bundle

Resources.images().get("image.png"); // Load image
Resources.sounds().get("sound.wav"); // Load sound
Resources.fonts().get("font.ttf", 24f); // Load font
Resources.spritesheets().get("player-idle"); // Get spritesheet

Entities

Creating

@EntityInfo(width = 32, height = 32)
@CollisionInfo(collision = true, collisionBoxWidth = 28, collisionBoxHeight = 28)
@MovementInfo(velocity = 100)
@CombatInfo(hitpoints = 50)
public class Enemy extends Creature {
  public Enemy() {
    super("enemy");
  }
}

Common Methods

entity.getName();
entity.getLocation();
entity.setLocation(x, y);
entity.getWidth() / entity.getHeight();
entity.getBoundingBox();
entity.getCenter();
entity.getTags();
entity.hasTag("enemy");

// Collision
collisionEntity.hasCollision();
collisionEntity.getCollisionBox();

// Combat
combatEntity.getHitpoints();
combatEntity.getMaxHitpoints();
combatEntity.hit(damage);
combatEntity.isDead();

// Movement
mobileEntity.getVelocity();
mobileEntity.setVelocity(100);
mobileEntity.getAngle();

Entity Events

entity.onAdded(e -> {...});
entity.onRemoved(e -> {...});
combatEntity.onHit(e -> {...});
combatEntity.onDeath(e -> {...});
mobileEntity.onMoved(e -> {...});
collisionEntity.onCollision(e -> {...});

Animation

entity.getAnimationController().play("walk");
entity.getAnimationController().getCurrentAnimation();

Screens

public class MenuScreen extends Screen {
  public MenuScreen() {
    super("MENU");
  }

  @Override
  protected void initializeComponents() {
    // Add GUI components
  }

  @Override
  public void render(Graphics2D g) {
    // Custom rendering
  }
}

Game.screens().add(new MenuScreen());
Game.screens().display("MENU");
Game.screens().current();

Tweens

Game.tweens().begin(entity, TweenType.LOCATION_XY, 1000)
.target(200, 300)
.ease(TweenFunction.QUAD_INOUT)
.begin();

Camera

Game.world().camera();
camera.setFocus(entity);
camera.setZoom(2f);
camera.getViewport();

Configuration

# config.properties
gfx_fullscreen=false
gfx_enableResolutionScale=true
cl_maxFps=60
cl_showGameMetrics=true
client_updaterate=60

Common Patterns

Basic Game Setup

public static void main(String[] args) {
  Game.info().setName("My Game");
  Game.init(args);
  Resources.load("game.litidata");
  Game.world().loadEnvironment("level1");
  Game.start();
}

Entity with Update Logic

public class Enemy extends Creature implements IUpdateable {
  public Enemy() {
    super("enemy");
    Game.loop().attach(this);
  }

  @Override
  public void update() {
    if (isDead()) {
      Game.loop().detach(this);
      return;
    }
    // AI logic
  }
}

Custom Movement Controller

@Override
protected IMovementController createMovementController() {
  KeyboardEntityController<Player> c = new KeyboardEntityController<>(this);
  c.addUpKey(KeyEvent.VK_W);
  c.addDownKey(KeyEvent.VK_S);
  c.addLeftKey(KeyEvent.VK_A);
  c.addRightKey(KeyEvent.VK_D);
  return c;
}