reckfellENGINE

Your first C# script

Attach a script to Sprite2D, build the project and set rotation speed in the inspector.

On this page

Preparation

Use a C# project from project setup. This example is 2D: create a prefab with a Sprite2D root and assign its Texture, for example by dragging icon.svg from the Content Browser. Move the root to (320, 180) so the image is inside the game window. Save as Spinner.rprefab.

Attach the script

Select Sprite2D, use the hierarchy's attach-script button and create SimpleSpinner.cs with base class Entity2D. Sprite2D inherits Entity2D, so this is a valid extension. Confirm creation of a C# solution if prompted.

Replace the entire file:

C#
using Reckfell;

public partial class SimpleSpinner : Entity2D
{
    [Export] public float DegreesPerSecond { get; set; } = 45.0f;

    public override void _Process(double delta)
    {
        Rotation += Mathf.DegToRad(DegreesPerSecond) * (float)delta;
    }
}

The file must match the class name: SimpleSpinner.cs. A file in the project folder does not attach behavior to an entity by itself.

Build and run

  1. Save the code and choose Build Project in the C# tools; the default shortcut is Alt + B.
  2. Wait for a successful build, save the prefab and press F6.
  3. The image should rotate 45 degrees per second. F8 stops the game.

_Process() runs each frame. delta is the frame duration in seconds; multiplying by it converts a speed into a change for this frame. Rotation uses radians, hence Mathf.DegToRad().

Change the speed

Stop the game, select the root and set Degrees Per Second in the inspector: 90 doubles the speed, -45 reverses direction and 0 stops it. [Export] exposes the property after building. A saved inspector value takes precedence over the initial value in code.

If the image is missing, check Texture, visibility and position. If it is stationary, check the latest build, script attachment and a nonzero speed. See C# troubleshooting and entity lifecycle.

Reckfell Engine documentationBack to top ↑
QUICK LINKSGetting startedEntity hierarchyC# & .NET 10Scenes and prefabs
Reckfell guides and full API K
reckfellENGINE
RECKFELL ACCOUNT

Sign in

Sign in to your Reckfell account.

One account for the entire Reckfell platform.