Skip to content
This repository has been archived by the owner on Dec 17, 2022. It is now read-only.

sirdx/Candle.NET

Repository files navigation

logo

Candle.NET

2D lighting for SFML.NET

Candle.NET is a SFML based C# library that provides light, shadow casting and field of view functionalities with easy integration. It is originally written in C++, and this project is its version for .Net languages.

There is no tutorial for Candle.NET, but you can use the C++ resources.

Official documentation, C++ version.

Authors

Demo

Before anything, here you have a little example of how it looks.

The code comes with a demo program showing the functionalities provided by the library. In it you can place lights and edges that will cast shadows, and modify the behaviour of the fog.

You can check the full manual of the demo here.

Contributing

This project is more likely to only be a .Net version of the existing library. Meaning, any functionality which is not in the original Candle won't be added here.

However, if you want to improve the code or add support for more .Net versions, then you are free to go.

Example

With SFML.Net and Candle.NET installed you can run the following code:

using SFML.Graphics;
using SFML.System;
using SFML.Utils;
using SFML.Window;
using Candle;

namespace Demo
{
    public class Example
    {
        static void Main(string[] args)
        {
            // Create a window
            RenderWindow window = new RenderWindow(new VideoMode(400, 400), "app");
            window.Closed += (s, e) => window.Close();

            // Create a light source
            RadialLight light = new RadialLight()
            {
                Range = 150F
            };

            // Create an edge pool
            List<Line> edges = new List<Line>
            {
                new Line(new Vector2f(200F, 100F), new Vector2f(200F, 300F))
            };

            window.MouseMoved += (s, e) =>
            {
                light.Position = (Vector2f)Mouse.GetPosition(window);
                light.CastLight(edges);
            };

            // Main loop
            while (window.IsOpen)
            {
                window.DispatchEvents();

                window.Clear();
                window.Draw(light);
                window.Display();
            }
        }
    }
}

The result will be a simple light casting a shadow over an invisible wall in the center of the window.

License

Candle uses the MIT license, a copy of which you can find here, in the repo.

It uses the external library SFML, that is licensed under the zlib/png license.

About

2D lighting library for SFML.Net

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published