Animated Entities

SadConsole supports entities with animations, there isn’t much difference between making a general animation or animating an entitiy. An entity basically uses an AnimatedScreenSurface to render its animation.

Creating an entity with an AnimatedScreenSurface

Similar to an animation, lets start with creating a custom animation for the player entity.

// Create new animation
var animation = new AnimatedScreenSurface("Player", 1, 1)
{
	AnimationDuration = 1f,
	Font = Game.Instance.StartingConsole.Font
};
animation.Surface.DefaultBackground = Color.Transparent;
animation.Surface.DefaultGlyph = '@';

Lets build a flicker effect similar to the Blinker component.

// Create flicker effect
var frame = animation.CreateFrame();
frame[0, 0].Foreground = Color.Blue;
frame = animation.CreateFrame();
frame[0, 0].Foreground = Color.Cyan;
animation.Repeat = true;

Now we just create the player entity with this animation.

// Create player entity with this animation
var playerEntity = new Entity(animation, zIndex: 0)
{
	Name = "Player",
	Position = new Point(5, 5)
};
entityManager.Add(playerEntity);

// Start animation, it runs forever (repeated)
animation.Start();

Thats it, fairly simple to animate entities.

Leave a comment

Design a site like this with WordPress.com
Get started