Playfield Script API
すべての API 関数は 1 つのパラメータを取ります。 そのパラメータは辞書でなければならず、引数はキーと値のペアとして格納されます。
骨組み
func setup() {
return {
width: 1920,
height: 1080,
title: "My Game"
};
}
func start() {
playerTex = Engine.loadTexture({
file: "player.png"
});
}
func frame() {
Engine.draw({
texture: playerTex,
x: Engine.mousePosX,
y: Engine.mousePosY
});
}
デバッグ
print()
この API は文字列を表示するか、オブジェクトをダンプします。 この API だけは、辞書でない引数を取ります。
func dumpEnemies() {
if (Engine.isGamepadXPressed) {
print("[Current emenies]");
print(enemies);
}
}
時間
絶対的な時間
変数 | 説明 |
---|---|
Engine.millisec | 起動からの時間(ミリ秒) |
func frame() {
var dt = (Engine.millisec - lastTime) * 0.001;
update(dt);
render();
}
Engine.getDate()
日付を表す辞書を返します。
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;
}
入力
これらは変数であり、関数ではありません。
変数 | 説明 |
---|---|
Engine.mousePosX | マウスX座標 |
Engine.mousePosY | マウスY座標 |
Engine.isMouseLeftPressed | 左マウスボタン |
Engine.isMouseRightPressed | 右マウスボタン |
Engine.isKeyUpPressed | 上キー |
Engine.isKeyDownPressed | 下キー |
Engine.isKeyLeftPressed | 左キー |
Engine.isKeyRightPressed | 右キー |
Engine.isKeyReturnPressed | リターンキー |
Engine.isGamepadUpPressed | ゲームパッド上キー |
Engine.isGamepadDownPressed | ゲームパッド下キー |
Engine.isGamepadLeftPressed | ゲームパッド左キー |
Engine.isGamepadRightPressed | ゲームパッド右キー |
Engine.isGamepadAPressed | ゲームパッドボタン1 |
Engine.isGamepadBPressed | ゲームパッドボタン2 |
Engine.isGamepadXPressed | ゲームパッドボタン3 |
Engine.isGamepadYPressed | ゲームパッドボタン4 |
Engine.isGamepadLPressed | ゲームパッドボタン5 |
Engine.isGamepadRPressed | ゲームパッドボタン6 |
Engine.gamepadAnalogX1 | ゲームパッドアナログ1 X (-32768, 32767) |
Engine.gamepadAnalogY1 | ゲームパッドアナログ1 Y (-32768, 32767) |
Engine.gamepadAnalogX2 | ゲームパッドアナログ1 X (-32768, 32767) |
Engine.gamepadAnalogY2 | ゲームパッドアナログ1 Y (-32768, 32767) |
Engine.gamepadAnalogL | ゲームパッドアナログL (-32768, 32767) |
Engine.gamepadAnalogR | ゲームパッドアナログR (-32768, 32767) |
func update() {
if (Engine.isMouseLeftPressed) {
player.x = player.x + 100;
}
}
レンダリング
Engine.createColorTexture()
この API は指定された色のテクスチャを作成して返します。
引数名 | 説明 |
---|---|
width | テクスチャの幅 |
height | テクスチャの高さ |
r | 色の R 値 (0-255) |
g | 色の G 値 (0-255) |
b | 色の B 値 (0-255) |
a | アルファ値 (0-255) |
func createBlockTexture() {
blockTex = Engine.createColorTexture({
width: 16,
height: 16,
r: 255,
g: 255,
b: 255,
a: 255
});
}
Engine.loadTexture()
この API はアセットからテクスチャをロードし、テクスチャを返します。
引数名 | 説明 |
---|---|
file | ロードするファイルの名前 |
func loadPlayerTexture() {
playerTex = Engine.loadTexture({
file: "player.png"
});
var width = playerTex.width;
var height = playerTex.height;
}
Engine.destroyTexture()
この API はテクスチャを破棄します。
引数名 | 説明 |
---|---|
texture | テクスチャ |
func destroyPlayerTexture() {
Engine.loadTexture({
texture: playerTex
});
}
Engine.renderTexture()
この API はテクスチャをスクリーンに描画します。
引数名 | 説明 |
---|---|
dstLeft | スクリーン X 座標 |
dstTop | スクリーン Y 座標 |
dstWidth | スクリーンでの幅 |
dstHeight | スクリーンでの高さ |
texture | テクスチャ |
srcLeft | テクスチャの左上 X 座標 |
srcTop | テクスチャの左上 Y 座標 |
srcWidth | テクスチャ矩形の幅 |
srcHeight | テキスチャ矩形の高さ |
alpha | アルファ値 (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()
この API はテキスチャをスクリーンに描画します。
Engine.renderTexture()
のシンプル版です。
引数名 | 説明 |
---|---|
texture | テクスチャ |
x | スクリーン X 座標 |
y | スクリーン Y 座標 |
func renderPlayer() {
Engine.draw({
texture: playerTex,
x: playerPos.x,
y: playerPos.y
});
}
Engine.renderTexture3D()
この API はテクスチャを 3D 変形してスクリーンに描画します。
引数名 | 説明 |
---|---|
x1 | スクリーン座標 X1 |
y1 | スクリーン座標 Y1 |
x2 | スクリーン座標 X2 |
y2 | スクリーン座標 Y2 |
x3 | スクリーン座標 X3 |
y3 | スクリーン座標 Y3 |
x4 | スクリーン座標 X4 |
y4 | スクリーン座標 Y4 |
texture | テクスチャ |
srcLeft | テクスチャ左上 X 座標 |
srcTop | テクスチャ左上 Y 座標 |
srcWidth | テクスチャ矩形の幅 |
srcHeight | テクスチャ矩形の高さ |
alpha | アルファ値 (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()
この API はフォントファイルをフォントスロットにロードします。
Argument Name | Description |
---|---|
slot | フォントスロット番号 (0-3) |
file | ロードするファイルの名前 |
func loadNotoSansFont() {
Engine.loadFont({ slot: 0, file: "NotoSans.ttf" });
}
Engine.createTextTexture()
この API はテキストを描画したテクスチャを描画します。
引数名 | 説明 |
---|---|
slot | フォントスロット番号 (0-3) |
text | 描画するテキスト |
size | フォントサイズ |
r | 色の R 値 (0-255) |
g | 色の G 値 (0-255) |
b | 色の B 値 (0-255) |
a | アルファ値 (0-255) |
func createScoreTexture() {
scoreTex = Engine.createTextTexture({
slot: 0,
text: "Score: " + score,
size: 32,
r: 255,
g: 255,
b: 255,
a: 255
});
}
サウンド
Engine.playSound()
この API はサウンドをサウンドトラック上で再生します。
引数名 | 説明 |
---|---|
stream | トラック番号 (0-3) |
file | 再生するファイルの名前 |
func playJumpSound() {
Engine.playSound({ stream: 0, file: "jump.ogg" });
}
Engine.stopSound()
この API はサウンドトラック上のサウンド再生を停止します。
引数名 | 説明 |
---|---|
stream | Track index. (0-3) |
func playJumpSound() {
Engine.stopSound({ stream: 0 });
}
Engine.setSoundVolume()
この API はサウンドトラックのボリュームを設定します。
引数名 | 説明 |
---|---|
stream | トラック番号 (0-3, -1 ならマスター) |
volume | ボリューム値 (0-1.0) |
func playJumpSound() {
Engine.setSoundVolume({
stream: 0,
volume: 1.0
});
}
セーブデータ
Engine.writeSaveData()
この API は文字列キーに対応するセーブデータ値を書き込みます。 セーブデータ値が大きすぎる場合、API は失敗します。
引数名 | 説明 |
---|---|
key | 文字列キー |
value | 値 (整数, 浮動小数点数, 配列, 辞書) |
Engine.readSaveData()
この API は文字列キーに対応するセーブデータ値を読み込みます。 戻り値はセーブデータ値を表すオブジェクトです。 文字列キーが存在しないとき、この API は失敗します。
引数名 | 説明 |
---|---|
key | 文字列キー |
Engine.checkSaveData()
この API はセーブデータの文字列キーが存在するかどうかをチェックします。 戻り値は boolean です。
引数名 | 説明 |
---|---|
key | 文字列キー |