2.1 KiB
2.1 KiB
Scripting
This page is a starting point for scripting documentation.
Overview
- Scripts live in
scripts/and are executed by AngelScript. - Predefined API and engine bindings are declared in
scripts/as.predefined.
Input Actions
- Query input with
IsActionPressed,IsActionDown,IsActionReleased, andGetActionStrength. - Register and bind at runtime with
RegisterAction,BindKeyboard,BindMouseButton,BindGamepadButton, andBindGamepadAxis. - Enums:
Key,MouseButton,GamepadButton,GamepadAxis.
Example:
RegisterAction("boost");
BindKeyboard("boost", Key::LEFT_CONTROL);
BindGamepadButton("boost", 0, GamepadButton::RIGHT_TRIGGER_1);
RegisterAction("zoom");
BindGamepadAxis("zoom", 0, GamepadAxis::RIGHT_TRIGGER, 0.2f, false);
ECS Texture + UV
- Texture and UV helpers live under the
ECS::namespace. - Texture:
AddTexture,SetTextureId,GetTextureId,HasTexture,RemoveTexture. - UV Transform:
AddUVTransform,SetUVScale,SetUVOffset,SetUVRotation,HasUVTransform,RemoveUVTransform.
Example:
uint e = ECS::CreateEntity();
ECS::AddTexture(e, texId);
ECS::AddUVTransform(e, 2.0f, 2.0f, 0.0f, 0.0f, 0.0f);
ECS::SetUVOffset(e, 0.25f, 0.0f);
Asset Manager
- Asset loading can be keyed for editor and scene usage.
- Use
Asset::Load*helpers to create assets and reference them by key.
Example:
Asset::LoadTexture("grid", "assets/textures/grid.png");
Asset::LoadShader("toon", "shaders/toon.vs", "shaders/toon.fs");
Asset::LoadCube("unit_cube", 1.0f, 1.0f, 1.0f);
Asset::CreateMaterial("toon_mat", Asset::GetShaderId("toon"), 255, 255, 255, 255);
uint e = ECS::CreateEntity();
ECS::AddModelRenderer(e, int(Asset::GetModelId("unit_cube")), 0xFFFFFFFF, 0.0f);
ECS::SetModelRendererShader(e, Asset::GetShaderId("toon"));
ECS::AddTexture(e, Asset::GetTextureId("grid"));
ECS::AddMaterial(e, Asset::GetMaterialId("toon_mat"));
Examples
scripts/game.as— demo showing ECS usage, rendering, scenegraph and input actions.
How to document APIs
Add Markdown pages in the docs/ folder. Use relative links and include code fences for examples.