Ray Low Level API

The Low Level API (Engine.*) is designed for versatile 2D game creation.

Every API function takes one parameter. The parameter must be a dictionary, and arguments must be stored as key-and-value pairs.

Skelton

// Do not define variables outside functions because it's a syntax error.

// Called when the window is created.
func setup() {
    // Return the window configuration.
    return {
        width: 1280,
        height: 720,
        title: "My First Game"
    };
}

// Called once when the game starts.
func start() {
    // Global variables should be defined here.
    posX = 0;
    posY = 0;

    // Create a white 100x100 texture.
    tex = Engine.createColorTexture({
        width: 100,
        height: 100,
        r: 255, g: 255, b: 255, a: 255
    });
}

// Called every frame before rendering.
func update() {
    posX = Engine.mousePosX;
    posY = Engine.mousePosY;
}

// Called every frame to render graphics.
func render() {
    Engine.draw({ texture: tex, x: posX, y: posY });
}

Debug

print()

This API prints a string or dumps an object. Only takes a non-dictionary argument.

func dumpEnemies() {
    if (Engine.isGamepadXPressed) {
        print("[Current emenies]");
        print(enemies);
    }
}

Time

Absolute Time

VariableDescription
Engine.millisecTime in millisec.
func update() {
    // Get the seconds since the last call.
    var curTime = Engine.millisec;
    var dt = (curTime - lastTime) * 0.001;
    lastTime = curTime;

    updateCharacters(dt);
}

Engine.getDate()

Returns a date dictionary.

func frame() {
    var date = Engine.getDate({});

    var year  = date.year;
    var month = date.month;
    var day   = date.day;
    var hour  = date.hour;
    var min   = date.minute;
    var sec   = date.second;
}

Input

These are variables, not functions.

VariableDescription
Engine.mousePosXMouse position X.
Engine.mousePosYMouse position Y.
Engine.isMouseLeftPressedLeft mouse button state.
Engine.isMouseRightPressedRight mouse button state.
Engine.isEscapeKeyPressedEscape key state.
Engine.isReturnKeyPressedReturn key state.
Engine.isSpaceKeyPressedSpace key state.
Engine.isTabKeyPressedTab key state.
Engine.isBackspaceKeyPressedBackspace key state.
Engine.isDeleteKeyPressedDelete key state.
Engine.isHomeKeyPressedHome key state.
Engine.isEndKeyPressedEnd key state.
Engine.isPageupKeyPressedPageUp key state.
Engine.isPagedownKeyPressedPageDown key state.
Engine.isShiftKeyPressedShift key state.
Engine.isControlKeyPressedControl key state.
Engine.isAltKeyPressedAlt key state.
Engine.isUpKeyPressedUp arrow key state.
Engine.isDownKeyPressedDown arrow key state.
Engine.isRightKeyPressedRight arrow key state.
Engine.isLeftKeyPressedLeft arrow key state.
Engine.isAKeyPressed'A' key state.
Engine.isBKeyPressed'B' key state.
Engine.isCKeyPressed'C' key state.
Engine.isDKeyPressed'D' key state.
Engine.isEKeyPressed'E' key state.
Engine.isFKeyPressed'F' key state.
Engine.isGKeyPressed'G' key state.
Engine.isHKeyPressed'H' key state.
Engine.isIKeyPressed'I' key state.
Engine.isJKeyPressed'J' key state.
Engine.isKKeyPressed'K' key state.
Engine.isLKeyPressed'L' key state.
Engine.isMKeyPressed'M' key state.
Engine.isNKeyPressed'N' key state.
Engine.isOKeyPressed'O' key state.
Engine.isPKeyPressed'P' key state.
Engine.isQKeyPressed'Q' key state.
Engine.isRKeyPressed'R' key state.
Engine.isSKeyPressed'S' key state.
Engine.isTKeyPressed'T' key state.
Engine.isUKeyPressed'U' key state.
Engine.isVKeyPressed'V' key state.
Engine.isWKeyPressed'W' key state.
Engine.isXKeyPressed'X' key state.
Engine.isYKeyPressed'Y' key state.
Engine.isZKeyPressed'Z' key state.
Engine.is1KeyPressed'1' key state.
Engine.is2KeyPressed'2' key state.
Engine.is3KeyPressed'3' key state.
Engine.is4KeyPressed'4' key state.
Engine.is5KeyPressed'5' key state.
Engine.is6KeyPressed'6' key state.
Engine.is7KeyPressed'7' key state.
Engine.is8KeyPressed'8' key state.
Engine.is9KeyPressed'9' key state.
Engine.is0KeyPressed'0' key state.
Engine.isF1KeyPressedF1 key state.
Engine.isF2KeyPressedF2 key state.
Engine.isF3KeyPressedF3 key state.
Engine.isF4KeyPressedF4 key state.
Engine.isF5KeyPressedF5 key state.
Engine.isF6KeyPressedF6 key state.
Engine.isF7KeyPressedF7 key state.
Engine.isF8KeyPressedF8 key state.
Engine.isF9KeyPressedF9 key state.
Engine.isF10KeyPressedF10 key state.
Engine.isF11KeyPressedF11 key state.
Engine.isF12KeyPressedF12 key state.
Engine.isGamepadUpPressedGamepad up arrow state.
Engine.isGamepadDownPressedGamepad down arrow state.
Engine.isGamepadLeftPressedGamepad left arrow state.
Engine.isGamepadRightPressedGamepad right arrow state.
Engine.isGamepadAPressedGamepad A button state.
Engine.isGamepadBPressedGamepad B button state.
Engine.isGamepadXPressedGamepad X button state.
Engine.isGamepadYPressedGamepad Y button state.
Engine.isGamepadLPressedGamepad L button state.
Engine.isGamepadRPressedGamepad R button state.
Engine.gamepadAnalogX1Gamepad analog 1 X (-32768, 32767)
Engine.gamepadAnalogY1Gamepad analog 1 Y (-32768, 32767)
Engine.gamepadAnalogX2Gamepad analog 2 X (-32768, 32767)
Engine.gamepadAnalogY2Gamepad analog 2 Y (-32768, 32767)
Engine.gamepadAnalogLGamepad analog L (-32768, 32767)
Engine.gamepadAnalogRGamepad analog R (-32768, 32767)
func update() {
    if (Engine.isMouseLeftPressed) {
        player.x = player.x + 100;
    }
}

Rendering

Engine.createColorTexture()

This API creates a texture with the specified color, and returns a texture.

Argument NameDescription
widthTexture width.
heightTexture height.
rRed color.
gGreen color.
bBlue color.
aAlpha color.
func createBlockTexture() {
    blockTex = Engine.createColorTexture({
                   width:  16,
                   height: 16,
                   r:      255,
                   g:      255,
                   b:      255,
                   a:      255
               });
}

Engine.loadTexture()

This API loads a texture from assets, and returns a texture.

Argument NameDescription
fileFile name to load.
func loadPlayerTexture() {
   playerTex = Engine.loadTexture({
                   file: "player.png"
               });

   var width = playerTex.width;
   var height = playerTex.height;
}

Engine.destroyTexture()

This API destroys a texture.

Argument NameDescription
textureTexture.
func destroyPlayerTexture() {
    Engine.loadTexture({
        texture: playerTex
    });
}

Engine.renderTexture()

This API renders a texture to the screen.

Argument NameDescription
dstLeftScreen coordinate X.
dstTopScreen coordinate Y.
dstWidthWidth in screen.
dstHeightHeight in screen.
textureTexture.
srcLeftTexture top left X.
srcTopTexture top left Y.
srcWidthTexture rectangle width.
srcHeightTexture rectangle height.
alphaAlpha value (0-255)
func renderPlayer() {
    Engine.renderTexture({
        dstLeft:   playerPos.x,
        dstTop:    playerPos.y,
        dstWidth:  playerTex.width,
	dstHeight: playerTex.height,
        texture:   playerTex,
        srcLeft:   0,
        srcTop:    0,
        srcWidth:  playerTex.width,
        srcHeight: playerTex.height,
        alpha:     255
    });
}

Engine.draw()

This API renders a texture to the screen (a simpler version of Engine.renderTexture().)

Argument NameDescription
textureTexture.
xScreen coordinate X.
yScreen coordinate Y.
func renderPlayer() {
    Engine.draw({
        texture: playerTex,
        x:       playerPos.x,
        y:       playerPos.y
    });
}

Engine.renderTexture3D()

This API renders a texture to the screen.

Argument NameDescription
x1Screen coordinate X1.
y1Screen coordinate Y1.
x2Screen coordinate X2.
y2Screen coordinate Y2.
x3Screen coordinate X3.
y3Screen coordinate Y3.
x4Screen coordinate X4.
y4Screen coordinate Y4.
textureTexture.
srcLeftTexture top left X.
srcTopTexture top left Y.
srcWidthTexture rectangle width.
srcHeightTexture rectangle height.
alphaAlpha value (0-255)
func renderPlayer() {
    Engine.renderTexture({
        dstLeft:   playerPos.x,
        dstTop:    playerPos.y,
        dstWidth:  playerTex.width,
	dstHeight: playerTex.height,
        texture:   playerTex,
        srcLeft:   0,
        srcTop:    0,
        srcWidth:  playerTex.width,
        srcHeight: playerTex.height,
        alpha:     255
    });
}

Engine.loadFont()

This API loads an asset font file to a specified font slot.

Argument NameDescription
slotFont slot index. (0-3)
fileFile name to load.
func loadNotoSansFont() {
    Engine.loadFont({ slot: 0, file: "NotoSans.ttf" });
}

Engine.createTextTexture()

This API creates a texture and draws a text on it.

Argument NameDescription
slotFont slot index. (0-3)
textText to draw.
sizeFont size.
rRed color.
gGreen color.
bBlue color.
aAlpha color.
func createScoreTexture() {
    scoreTex = Engine.createTextTexture({
                   slot: 0,
                   text: "Score: " + score,
                   size: 32,
                   r:    255,
                   g:    255,
                   b:    255,
                   a:    255
               });
}

Sound

Engine.playSound()

This API starts playing a sound asset file on a specified sound track.

Argument NameDescription
streamTrack index. (0-3)
fileFile to play.
func playJumpSound() {
    Engine.playSound({ stream: 0, file: "jump.ogg" });
}

Engine.playSoundLoop()

This API starts playing a sound asset file on a specified sound track.

Argument NameDescription
streamTrack index. (0-3)
fileFile to play.
func playBGM() {
    Engine.playSoundLoop({ stream: 0, file: "jump.ogg" });
}

Engine.stopSound()

This API stops a sound playback on a specified sound track.

Argument NameDescription
streamTrack index. (0-3)
func playJumpSound() {
    Engine.stopSound({ stream: 0 });
}

Engine.setSoundVolume()

This API sets a sound volume on a specified sound track.

Argument NameDescription
streamTrack index. (0-3, -1 for master)
volumeVolume value. (0-1.0)
func playJumpSound() {
    Engine.setSoundVolume({
        stream: 0,
        volume: 1.0
    });
}

Save Data

Engine.writeSaveData()

This API writes a save data value that corresponds to a key string. If the save data value is too large, this API will fail.

Argument NameDescription
keyKey string.
valueValue. (integer, floating point, array, or dictionary)

Engine.readSaveData()

This API reads save data value that corresponds to a key string. The return value will be an object that represents a save data value. This API will fail when the specified key is not available.

Argument NameDescription
keyKey string.

Engine.checkSaveData()

This API checks whether the save data exists for a key string or not. The return value is a boolean.

Argument NameDescription
keyKey string.