FlysEngine.Sprites

Bundled FlysEngine with Sprite functions and physics engine (from FarseerDuality).


Keywords
linqpad-samples, 2d-game-engine, sharpdx
License
Apache-2.0
Install
Install-Package FlysEngine.Sprites -Version 2.0.6

Documentation

FlysEngine NuGet QQ

Real-time 2D rendering utilities based on SharpDX/Direct2D.

Packages

Package runtimes NuGet Package
FlysEngine net6 NuGet
FlysEngine.Desktop net6 NuGet
FlysEngine.Sprites net6 NuGet

Simple example

(Refer to /tree/master/FlysTest)

  • Final result: Final Result
  • Create a Windows-form application
  • Delete the entire Form1 class
  • Install the FlysEngine nuget package
  • Install the SharpDX.Desktop nuget package for convenient
  • In Program.cs file, using following namespaces:
    using FlysEngine;
    using FlysEngine.Desktop;
    using FlysEngine.Managers;
    using Vortice.Direct2D1;
    using Vortice.DirectWrite;
    using Vortice.Mathematics;
    using FlowDirection = Vortice.DirectWrite.FlowDirection;
    using FontStyle = Vortice.DirectWrite.FontStyle;
  • Replace Main method's content to following code:
    using (var res = new XResource())
    using (var form = new Form() { Text = "Hello World" })
    {
        var timer = new RenderTimer();
        IDWriteTextFormat bottomRightFont = res.DWriteFactory.CreateTextFormat("Consolas", 16.0f);
        bottomRightFont.FlowDirection = FlowDirection.BottomToTop;
        bottomRightFont.TextAlignment = TextAlignment.Trailing;
    
        IDWriteTextFormat bottomLeftFont = res.DWriteFactory.CreateTextFormat("Consolas", FontWeight.Normal, FontStyle.Italic, FontStretch.Normal, 24.0f);
        bottomLeftFont.FlowDirection = FlowDirection.BottomToTop;
        bottomLeftFont.TextAlignment = TextAlignment.Leading;
    
        form.Resize += (o, e) =>
        {
            if (form.WindowState != FormWindowState.Minimized && res.DeviceAvailable)
            {
                res.Resize();
            }
        };
    
        RenderLoop.Run(form, () => Render());
    
        void Render()
        {
            if (!res.DeviceAvailable) res.InitializeDevice(form.Handle);
    
            var target = res.RenderTarget;
    
            timer.BeginFrame();
            target.BeginDraw();
            Draw(target);
            target.EndDraw();
            res.SwapChain.Present(1, 0);
            timer.EndFrame();
        }
    
        void Draw(ID2D1DeviceContext target)
        {
            target.Clear(Color4.CornflowerBlue);
            RectangleF rectangle = new RectangleF(0, 0, target.Size.Width, target.Size.Height);
    
            target.DrawRectangle(
                new RectangleF(10, 10, target.Size.Width - 20, target.Size.Height - 20),
                res.GetColor(Color4.Blue));
    
            target.DrawText("😀😁😂🤣😃😄😅😆😉😊😋😎",
                res.TextFormats[36], rectangle, res.GetColor(Color4.Blue),
                DrawTextOptions.EnableColorFont);
    
            target.DrawText("FPS: " + timer.FramesPerSecond.ToString("F1"),
                bottomRightFont, rectangle, res.GetColor(Color4.Red));
    
            target.DrawText("Hello World",
                bottomLeftFont, rectangle, res.GetColor(Color4.Purple));
        }
    }
  • Compile and run.

License

Apache License 2.0