How to create an Entity
SadConsole.Entities.Entity type provides a simple way to independently track text objects.
Entities are very similar to consoles, but they have a different purpose. Where a console provides features related to typing, mouse handling, and a virtual cursor, the
Entity type provides simple animation management. By default, the entity doesn’t do anything with the keyboard or mouse.
Entities are positioned objects that do not have a width or height. However, when an entity is drawn, it draws a
SadConsole.Surfaces.Animated object, which does have a width and height. This is defined by the
The animation is made up of individual frames. When you call the
SadConsole.Surfaces.Animated.CreateFrame method, you’re returned a
SadConsole.Surfaces.BasicNoDraw type which represents the surface array of cells. You can edit that animation frame as you would any other surface or console in SadConsole. Every time you call
CreateFrame, you create a new frame in the animation. When you’re finished, you have multiple frames that make up the animation.
The total amount of time it takes to play all frames is in seconds, and is set with the
The following example demonstrates how to create a basic animation and add it to an entity.
First, declare a variable to hold our entity.
private SadConsole.Entities.Entity fallingText;
Next, initialize the entity, create an animation, attach the animation to the entity, and position the entity.
// Height of 5, one line for each frame
You should see the following animation:
Next, read through this tutorial to understand how to draw an entity with a console.