Getting started

This guide will show you how to get started with the Apos.Shapes library.

Before you start, make sure that you have a valid MonoGame project. You can create a new project by following this other guide.

You can run this example directly in your browser here.

Install

Install using the following dotnet command:

dotnet add package Apos.Shapes

You can find other ways to install it on the NuGet page.

The library ships with a precompiled shader that is embedded in its assembly. Nothing gets added to your content pipeline and no shader compiler (or Wine on Linux / macOS) is needed. The minimum supported MonoGame version is 3.8.2.

Setup

Import the library with:

using Apos.Shapes;

In your game’s constructor, set the GraphicsProfile to HiDef. (If you’re using this library with KNI, set it to FL10_0 instead.) This enables the features that the shader will use. By default, MonoGame uses the Reach profile.

public Game1() {
    _graphics = new GraphicsDeviceManager(this);

    _graphics.GraphicsProfile = GraphicsProfile.HiDef;
}

In your game’s LoadContent(), create a ShapeBatch instance:

protected override void LoadContent() {
    _sb = new ShapeBatch(GraphicsDevice);
}

ShapeBatch _sb;

In your game’s draw loop, call Begin and End and do your drawing between those two calls:

protected override void Draw(GameTime gameTime) {
    GraphicsDevice.Clear(Color.Black);

    _sb.Begin();

    _sb.FillCircle(new Vector2(200, 100), 50, Color.White);

    _sb.End();

    base.Draw(gameTime);
}

A white circle on a black background

Everything that is drawn within the Begin and End calls will be batched together.

Follow up

Shapes, a page that lists every shape that the ShapeBatch can draw.

Edit this page on GitHub