Basic Guide To Engine Concepts

Basics

Canvas

The canvas in Dinghy uses the traditional 2D coordinate space where the top left of the screen is 0,0 and the bottom right is width,height.

Entities

An “Entity” is basically any “object” in the engine. Entities can be almost anything and don’t have to be visual. Dinghy ships with a few basic entity types (see below).

All entites have an X,Y coordinate, a pivot point, a scale, and a rotation.

Shape

A shape is a simple square block of color.

Sprite

A sprite is a static textured rectangle. These can be used for things like backgrounds or large static assets.

Animated Sprite

An Animated Sprite is a sprite that animates based on the passed in Animations.

Rect

A Rect is just a type to encapsulate an X,Y position and a width/height.

Animation

An Animation is a list of Rects that are used to find specific sections of a Texture for playback.

Particle Emitter

A particle emitter emits particles based on the passed in configuration.

Components

Any given entity shares only a few common characteristics, but differ in what additional components they have attached to them. For now, just use the basic entity types (see above).

Resources

Resource types (currently only Texture) are assets that are loaded into the engine for use by entities. This can happen automagically (see “Res Folder”) below.

Colors/Palettes

Colors can be defined via the constructor, but also implicitly created via hex-coded uints, meaning you can easily import palettes from .hex files from sites like lospec. Note that Dinghy expects palettes to be RGBA, so you may need to alter to downloaded hex values (lospec exports ARGB).

Interaction

Input

See the sample code for this, but basically you can easily grab mouse position and input callbacks from the Input class.

Colliders

Sprites (Animated and not) and Shapes have implicit colliders attached to them that are the size of the default Rect for that object based on its size. You can toggle the collider on/off using ColliderActive.

Physics

Physics are in the engine but right now a little onerous to setup. See the sample code for an example.

Scenes

Scenes are an organizing unit for games. They are not required but will (probably?) make your life easier. Scenes move through states as they are prepared to be used:

Target Scene is a phrase that comes up a bit. This is the scene that will actively have new entites added to it.

Scene Mount Status

After creating a scene, a scene is Unmounted. This means you can’t do anything with the scene. Mount the scene to be able to started adding entities to it.

When you unmount a scene, it destroys any entites that were added to it.

Scene Load Status

Scenes have a Preload override where you can basically “prepare” your scene before actually doing anything/showing anything. This is a good place to load in assets from disk. There is a load callback you can tie into to take action after loading.

Running a scene

After a scene is mounted and loaded, it can be run by calling Start() on the scene.

Scene Quickstart

You can do all of this in two function calls (should maybe make one function call like MountAndLoad()?):

scene.Mount(0);
scene.Load(() => scene.Start());

ImGUI

Dinghy has DearImGUI built in. This is a nice way to quickly debug your running game. Some ImGUI functions have pre-existing wrappers in ImGUIHelper.Wrappers, otherwise you can directly access ImGUI in Dinghy.Internal.Sokol.ImGUI but that’s a compliated API path. If you want new ImGUI functions, tell me and I can wrap them for you.

Live Editing

Leveraging ImGUI, you can call Quick.DrawEditGUIForObject() on objects and see a panel to edit the values at runtime for that object. Note that these values don’t currently save/load so you need to provide your own mechanism if you want to do that.

Utils

Grid

A nice helper class is Grid, which provides the ability to quickly lay out objects in a grid. The grid itself can be rotated/scaled.

Transition

Transitions are basically tweens that allow you to map a value to a given function (mainly easings from easings.net right now). Best when also combined with Util.MapValue to set an input range and output range for a value.

Debug View

There is a WIP debug view you can access by clicking the “draw debug” in the top Dinghy menu. For now this just shows entity id, their size, and their collider (in white)

Magic

Res folder

This is the first taste of the planned “Magic” of Dinghy and requires two things.

  1. First, place a folder called “res” in the root of your project folder.
  2. Second, add this text to your .csproj file:
    <ItemGroup>
        <AdditionalFiles Include="res\**\*"/>
        <Content Include="res\**\*">
            <CopyToOutputDirectory>Always</CopyToOutputDirectory>
        </Content>
    </ItemGroup>

After doing this (you may need to reload your solution), any png asset in that folder or subdirectory will be available directly in C# via code like (where conscript.png is in my res/ folder):

var tex = Res.Assets.conscript.CreateSprite();

Much more to come on this!

ECS

Dinghy works on the backend off of an ECS system. You can tie into this relatively easy, but TBD on how much I want to expose that.