How to create a GameObject
SadConsole.GameHelpers.GameObject type provides a simple way to independently track text objects.
Game objects are very similar to consoles, but they have a different focus. Where a console provides features related to typing, mouse handling, and a virtual cursor, the
GameObject type provides simple animation management. By default, the game object type doesn’t do anything with the keyboard or mouse.
The game object presents a single animation to the screen when rendered. The
GameObject.Animation property is the
SadConsole.Surfaces.AnimatedSurface type. The animation defines the size of the game object.
The animation is used to create individual frames. When you call the
AnimatedSurface.CreateFrame method, you’re returned a
SadConsole.Surfaces.BasicSurface type which represents the surface array of cells. You can modify the cells individually or you can provide that frame to a
SadConsole.Surfaces.SurfaceEditor type for helpful editing methods (SetBackground, Print, SetGlyph, etc).
The total amount of time it takes to play all frames is in seconds and is set on the
The following example demonstrates how to create a basic animation and add it to an game object. The animation is text that moves down the object.
First, declare a variable to hold our game object.
private SadConsole.GameHelpers.GameObject fallingText;
Next, initialize the game object, create an animation, attach the animation to the game object, and position the game object.
fallingText = new SadConsole.GameHelpers.GameObject();
During each update and render pass, you need to call
GameObject.Draw. You could do this in a derived console that overrides the render and update methods.
Next, read through this tutorial to understand how to draw an entity with a console.