Make a scene you can control
Turn the empty project into a small interactive result: one cube, a camera looking toward it and a key that moves it. This is a source-checked example for the current development API, not a compile-tested sample distributed with this guide.
Start from the first project
Use the first-game project from getting started. Keep engine-source beside it. Stop the running game before changing the source, and preserve any work you have already added; the replacement below is for the untouched starter only.
The scaffold already depends on app and pack. Add these entries to its existing [dependencies] section in first-game/Cargo.toml:
assets = { path = "../engine-source/code/crates/assets" }
glam = "0.34.1"
Do not create a second [dependencies] heading. If your checkout is elsewhere, adjust the assets path to reach the same engine checkout as the existing app dependency. The path is relative to the game's Cargo.toml.
Add the object and control
Replace the untouched starter's src/main.rs with:
use app::{Context, Game, MeshId, Transform};
use app::input::named_key;
use assets::Mesh;
use glam::Vec3;
struct FirstScene;
impl Game for FirstScene {
fn init(&mut self, ctx: &mut Context) {
ctx.meshes.push(Mesh::cuboid(Vec3::splat(0.5)));
let cube = ctx.world.spawn();
ctx.world.insert(cube, Transform::at(Vec3::ZERO));
ctx.world.insert(cube, MeshId(0));
ctx.view = glam::camera::rh::view::look_at_mat4(
Vec3::new(3.0, 2.0, 4.0),
Vec3::ZERO,
Vec3::Y,
);
}
fn update(&mut self, ctx: &mut Context) {
if ctx.input.held(named_key("ArrowRight").unwrap()) {
let cube = ctx.world.query2::<Transform, MeshId>()
.find(|(_, _, mesh)| mesh.0 == 0)
.map(|(entity, _, _)| entity);
if let Some(entity) = cube {
if let Some(transform) = ctx.world.get_mut::<Transform>(entity) {
transform.position.x += 2.0 * ctx.dt;
}
}
}
if ctx.input.just_pressed(named_key("Escape").unwrap()) {
ctx.exit = true;
}
}
}
fn main() {
app::run(FirstScene);
}
This uses an ordinary game update, not a special editor command. The mesh is created during initialization, when the standard runner uploads the initial mesh list. The visible entity combines a transform with MeshId(0), which selects the first mesh; the mesh index is not the entity's identity.
The camera starts at (3, 2, 4) and looks at the world origin. Holding the right arrow changes the cube's world-X position by 2 × ctx.dt per update. Native frame delta is capped at 0.1 seconds, while the harness uses fixed 1/60-second updates. It is not camera-relative movement, and this example does not add collision or physics.
Run and check the result
From the original working folder:
AIGameEngine run --project ./first-game
Check these outcomes:
- The cube is visible near the middle of the window.
- Holding the right arrow moves it.
- Releasing the key stops the movement.
- Escape requests that the native game exit.
These are the intended outcomes supported by the API, not results observed during the writing of this guide. Read any build or runtime error before assuming a visual failure is a control problem.
Tip. The cube can move out of view because the camera stays still. Restarting this example resets it to the origin. A disappearing cube after a long key press is not proof that the mesh was deleted.
Understand the three decisions
| Decision | Why it matters |
|---|---|
Create the mesh in init |
The standard runner uploads that initial list. Appending CPU meshes later is not, by itself, a runtime GPU-upload workflow. |
| Find the entity, then change its transform | Game objects carry components. Changing a mesh index is not moving an object. |
Use ctx.dt |
Movement is expressed as a rate rather than a fixed distance for every rendered frame. |
The example finds the only object using mesh zero. In a larger game, keep a deliberate reference or component identifying the player; otherwise several objects sharing a mesh make that query ambiguous.
Warning. If you later attach a physics body, manually changing only the render transform may not move the physics object. Physics synchronization can replace that transform. Choose a physics-aware movement method rather than combining the two ownership models accidentally.
If it does not work
- A missing
assetsdependency means the additional dependency was not added to the game's existing dependency section, or its engine path is wrong. - A camera or math API error can indicate an API/version mismatch. Use dependencies from the same engine checkout instead of mixing copied examples from another revision.
- A blank window needs a mesh, an in-range mesh index, a transform and a camera that can see it. Check those before adding more objects.
- No movement while the game is unfocused can be a window-input issue. Focus the window first, or use the native harness for explicit input injection.
- In a browser build, exiting and input focus behave differently; do not use the native Escape-exit check as a browser test.
You now have a minimal visible interaction. Next, plan the first actual game milestone, then learn how time and input affect behavior.