bounce-engine

Bounce Engine API Documentation

Table of Contents

  1. Core Classes
  2. Rendering
  3. Physics
  4. Input
  5. Audio
  6. Animation
  7. Particles
  8. UI
  9. Utilities

Core Classes

Engine

Main game engine class that manages the game loop and scenes.

Constructor

new Engine(config)

Parameters:

Properties

Methods

start() Starts the game loop.

stop() Stops the game loop.

pause() Pauses the game.

resume() Resumes the game.

addScene(name, scene) Adds a scene to the engine.

setScene(name) Switches to a different scene.

resize(width, height) Resizes the canvas.

destroy() Destroys the engine and cleans up resources.


Scene

Container for game objects and game state.

Constructor

new Scene(name)

Parameters:

Properties

Methods

add(gameObject) Adds a game object to the scene.

remove(gameObject) Removes a game object from the scene.

findByName(name) Finds a game object by name.

findByTag(tag) Finds all game objects with a tag.

clear() Removes all game objects.

onEnter() Called when scene becomes active. Override in subclass.

onExit() Called when scene becomes inactive. Override in subclass.


GameObject

Base class for all game entities.

Constructor

new GameObject(x, y)

Parameters:

Properties

Methods

addComponent(component) Adds a component to the game object.

getComponent(ComponentClass) Gets a component by type.

getComponents(ComponentClass) Gets all components of a type.

removeComponent(component) Removes a component.

addChild(child) Adds a child object.

removeChild(child) Removes a child object.

getWorldPosition() Gets world position accounting for parent transforms.

destroy() Destroys this game object.


Component

Base class for all components.

Constructor

new Component()

Properties

Methods

onStart() Called when component is added to a game object. Override in subclass.

fixedUpdate(dt) Fixed update for physics. Override in subclass.

update(dt) Update game logic. Override in subclass.

render(ctx) Render the component. Override in subclass.

onDestroy() Called when component is destroyed. Override in subclass.


Rendering

Camera

Manages viewport and camera transformations.

Constructor

new Camera(x, y, width, height)

Methods

follow(target, speed) Makes camera follow a game object.

setBounds(x, y, width, height) Sets camera movement bounds.

shake(intensity, duration) Creates camera shake effect.

update(dt) Updates camera (follow, shake, etc.)

screenToWorld(screenX, screenY) Converts screen coordinates to world coordinates.

worldToScreen(worldX, worldY) Converts world coordinates to screen coordinates.


SpriteRenderer

Renders sprites or colored rectangles.

Constructor

new SpriteRenderer(config)

Parameters:

Methods

setSprite(x, y, width, height) Sets sprite from sprite sheet.


TextRenderer

Renders text.

Constructor

new TextRenderer(text, config)

Parameters:


Physics

RigidBody

Adds physics properties to a game object.

Constructor

new RigidBody(config)

Parameters:

Properties

Methods

addForce(x, y) Applies a continuous force.

addImpulse(x, y) Applies an instant impulse.

setVelocity(x, y) Sets velocity directly.


BoxCollider

Axis-aligned box collider.

Constructor

new BoxCollider(width, height, offset)

Parameters:

Properties

Methods

onCollisionEnter(other) Called when collision starts. Override.

onCollisionStay(other) Called while colliding. Override.

onCollisionExit(other) Called when collision ends. Override.


CircleCollider

Circle collider.

Constructor

new CircleCollider(radius, offset)

Physics

Physics system managing simulation and collision detection.

Constructor

new Physics(scene)

Properties

Methods

addCollider(collider) Registers a collider.

removeCollider(collider) Unregisters a collider.

detectCollisions() Performs collision detection. Call each frame.

raycast(x, y, dirX, dirY, distance) Performs a raycast.


Input

Input

Manages keyboard, mouse, touch, and gamepad input.

Constructor

new Input(canvas)

Methods

update(camera) Updates input state. Call once per frame.

isKeyDown(keyCode) Checks if key is currently pressed.

isKeyPressed(keyCode) Checks if key was just pressed this frame.

isKeyReleased(keyCode) Checks if key was just released this frame.

isMouseButtonDown(button) Checks if mouse button is pressed.

isMouseButtonPressed(button) Checks if mouse button was just pressed.

isMouseButtonReleased(button) Checks if mouse button was just released.

getGamepad(index) Gets gamepad by index.

isGamepadButtonDown(button, gamepadIndex) Checks if gamepad button is pressed.

getGamepadAxis(axis, gamepadIndex) Gets gamepad axis value.

mapAction(actionName, mapping) Maps an action to inputs.

isActionDown(actionName) Checks if action is active.

isActionPressed(actionName) Checks if action was just pressed.

getAxis(actionName) Gets axis value for action.


Audio

Audio

Manages audio playback.

Methods

init() Initializes audio context. Must be called after user interaction.

loadSound(name, url) Loads a sound.

playSound(name, options) Plays a sound effect.

playMusic(name, options) Plays background music.

stopMusic() Stops music.

setMasterVolume(volume) Sets master volume (0-1).

setMusicVolume(volume) Sets music volume (0-1).

setSfxVolume(volume) Sets sound effects volume (0-1).


Animation

Animator

Manages sprite animations.

Constructor

new Animator(spriteRenderer)

Methods

addAnimation(name, animation) Adds an animation.

play(name, restart) Plays an animation.

stop() Stops animation.


Tween

Animates object properties over time.

Constructor

new Tween(target, to, duration, options)

Parameters:

Static Properties

Tween.Easing Built-in easing functions:


Full engine reference available at https://bounceforge.github.io/bounce-engine