Variables

Pockety has the following variables available for peruse. These should be considered read only, so don’t try and change them or bad things can happen.

The only exception to this is the debugCollisions variable, that can be set true or false at your leisure.

// utilities
isRunning = "is the engine running?"
isMobile = "is the engine running on a mobile device?"
center = "a Vector2 that holds the center of the canvas: {x, y}"
deltaTime = "the time in milliseconds between two frames"
debugCollisions = "are we drawing the colliders on screen?"

// scenes
scenes = "[] array of all the Scenes added to the engine"
activeScene = "the currently active Scene"

// audio and images
audioClips = "[] array of all the audio files loaded in the engine"
sprites = "same as above, but for the images"

// mouse
touching = "is the user touching or clicking?"
mousePosition = "a Vector2 indicating the mouse (or touch) position: {x, y}"

Functions

At the core of the engine we have it’s functions.

These will help us with dealing with assets, managing scenes, processing input and drawing on the screen.

It may seem a lot, but you’ll see that each section has just a handle of essential functions for you to use, let’s get into it!

// creating a **new** Pockety, requires a WIDTH and a HEIGHT.
// these can be numbers (in pixels) or can be set to "auto"
// if so, the canvas will expand to fit its parent
constructor(WIDTH, HEIGHT)

Scenes

// starts the engine and loads the scene passed as argument
const Run(scene)

// loads the passed scene as the active Scene
// if the scene has an Init() function, it calls it to setup the Scene
// finally calls Start on each of the entities in the Scene
const LoadScene(scene)

Input

// Check if a key is pressed just this frame
// accepts regular characters as input:
const IsKeyPressed(key)

// checks if a key is held down, this is true not only when the key is pressed
// but all the time, until the key is released
const isKeyDown(key)

Example

The following code rotates the ship and shoots in the example Asteroids game

// turn left, key is held down
if (pockety.IsKeyDown("ArrowLeft")) {
  Ship.rotation -= Ship.turningSpeed * deltaTime;
}

// turn right, key is held down
if (pockety.IsKeyDown("ArrowRight")) {
  Ship.rotation += Ship.turningSpeed * deltaTime;
}

// shoot if Space is pressed
if (pockety.IsKeyPressed(" ")) {
    fireBullet();
  }