-
-
Notifications
You must be signed in to change notification settings - Fork 11
Create Entity
MrScautHD edited this page Oct 23, 2023
·
1 revision
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();
}
...
}
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) { }
}
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());
}
}
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));
}
}
Sparkle Engine - Visit the official Sparkle GitHub repository for the latest updates and source code.
Copyright © [Stellution Studios] | Licensed under the MIT License