Skip to content

Create Entity

MrScautHD edited this page Oct 23, 2023 · 1 revision

Create Entity

The entity system enables you to incorporate controlled objects into your scene. To get started, the initial step involves crafting a class that extends from the Entity class.

public class MyEntity : Entity {
    
    public MyEntity(Vector3 position) : base(position) { }

    protected override void Init() {
        base.Init();
    }

    protected override void Update() {
        base.Update();
    }

    protected override void AfterUpdate() {
        base.AfterUpdate();
    }

    protected override void FixedUpdate() {
        base.FixedUpdate();
    }

    protected override void Draw() {
        base.Draw();
    }
...
}

Create Component

To create a Component, simply extend the Component class.

public class MyComponent : Component {
    
    protected override void Init() {
        base.Init();
    }

    protected override void Update() {
        base.Update();
    }

    protected override void AfterUpdate() {
        base.AfterUpdate();
    }

    protected override void FixedUpdate() {
        base.FixedUpdate();
    }

    protected override void Draw() {
        base.Draw();
    }

    protected override void Dispose(bool disposing) { }
}

Entity add Components

You can easily include the component by employing the AddComponent method within the Entity class.

public class MyEntity : Entity {
    
    public MyEntity(Vector3 position) : base(position) { }

    protected override void Init() {
        base.Init();
        this.AddComponent(new MyComponent());
    }
}

Add your Entities to your Scenes

To add your entity to the scene, make use of the AddEntity method.

public class MyScene : Scene {
    
    public MyScene(string name) : base(name) { }

    protected override void Init() {
        base.Init();
        this.AddEntity(new MyEntity(Vector3.Zero));
    }
}
Clone this wiki locally