KROYSDOCS
HomeWhat's newv0.1.0
MANUAL / Editor / Play mode and input

Play mode and input

Play runs the scene in the Game panel with the same rules as the shipped game. Input goes through named actions that players can rebind.

PlayF5
StopShift Esc
Free cursorShift F1
PanelGame
01

Play and stop

Play (F5) copies the open scene into a play world and runs it in the Game panel: scripts, physics, animation, audio, UI. The scene you edit is untouched; whatever happens in Play is thrown away at Stop (Shift+Esc or the toolbar button). Character controllers start at the scene's Spawn Point.

02

Who owns the mouse

Play starts with the cursor captured by the game, as in a shipped game. While it is captured, the game gets the mouse and every key, Esc included, so pause menus work. Two chords always reach the editor:

ActionChord
Stop PlayShift+Esc
Free the cursor for the editor, and give it backShift+F1

A freed cursor returns to the game with a click into the Game panel. Scripts release it for menus with Game.SetCursorCaptured(false). Both chords can be rebound in Help › Keyboard Shortcuts.

03

Input actions

Scripts ask for actions, not keys. The project's input map (Content/Settings/Input.kinput) names actions and binds them to keys, mouse buttons, gamepad buttons and sticks; a project without one uses the defaults:

ActionDefault bindings
MoveWASD, the arrow keys, the left stick
Lookmouse motion
JumpSpace, gamepad south button
SprintShift, left stick press
CrouchC, right stick press
InteractE, gamepad west button
Fireleft mouse button, right trigger

Actions read in OnFixedUpdate report each press on exactly one fixed step, whatever the frame rate; read in OnUpdate, they follow the rendered frame. Contexts group bindings and can be pushed and popped (a vehicle, a menu). Players can rebind at run time with Input.Rebind and save with Input.SaveBindings. See Input.

InteractPrompt.cs
public sealed class InteractPrompt : EntityScript
{
    protected override void OnFixedUpdate(float fixedDeltaTime)
    {
        // Actions come from the project's input map (Content/Settings/Input.kinput):
        // "Move" is WASD, the arrow keys and the left stick; "Interact" is E or the west button.
        Vector2 move = Input.GetAxis2D("Move");
        if (move.LengthSquared() > 0.01f)
            Debug.Log($"moving {move.X:0.00}, {move.Y:0.00}");

        // In OnFixedUpdate every press is reported on exactly one fixed step.
        if (Input.IsActionPressed("Interact"))
            Debug.Log("interact");
    }

    protected override void OnUpdate(float deltaTime)
    {
        // Raw keys and the mouse are there too, for debug keys and tools.
        if (Input.IsKeyPressed(KeyCode.F3))
            Debug.Log($"mouse at {Input.MousePosition}, moved {Input.MouseDelta}");
        if (Input.IsGamepadConnected(0) && Input.IsGamepadButtonDown(GamepadButton.Start))
            Debug.Log("pause");
    }
}
04

Game view options

  • View › Live Game Preview In Edit keeps the Game panel rendering while you edit.
  • View › Animate Characters In Edit plays animators without pressing Play.
  • View › Show Editor Panels In Play keeps the panels visible while playing.

KroysEngine 0.1.0 documentation, built from the engine repository by Tools/BuildDocsSite.py.