Skip to content

02. Hello World

Yx edited this page Dec 19, 2018 · 7 revisions

Here I assume that you have the basic knowledge of C#, and you have installed Visual Studio.

This section will tell you how to start a Love2dCS project.

When beginning to write games using LÖVE, the most important parts of the API are the callbacks :

  • Love.Scene.Load : to do one-time setup of your game.

  • Love.Scene.Update : which is used to manage your game's state frame-to-frame.

  • Love.Scene.Draw : which is used to render the game state onto the screen.

By inheriting the class Scene and override the method void Load() void Update(dt) void Draw() , you can handle input from the user, and other aspects of a full-featured game.

1. Create a C# console application

2. Please install Love2dCS from NuGet to your Visual Studio first :

In the Visual Studio Solution Explorer window, right-click on the project node and you will see a new context menu, Manage NuGet Packages.

Clicking on this menu will bring up the Manage NuGet Packages dialog. The dialog defaults to show packages that are installed in your project and have updates available on the office package source, as seen in below. The package source is a publicly hosted server on the Internet that hosts both open-source and closed-source libraries and components.

002-right-click-project

And click Browse, type Love2dCS in search box. And then you get result :

003-search-result

Click Install to setup Love2dCS library.

(More detail)

3. Put the following code in the file(maybe Program.cs), and save it.

using Love;
namespace Example
{
    class Program : Love.Scene
    {
        float x, y, w, h;
        public override void Load()
        {
            x = 20;
            y = 20;
            w = 60;
            h = 20;
        }

        public override void Update(float dt)
        {
            w = w + 1;
            h = h + 1;
        }

        public override void Draw()
        {
            Graphics.SetColor(0, 0.3f, 0.3f);
            Graphics.Rectangle(DrawMode.Fill, x, y, w, h);
        }

        static void Main(string[] args)
        {
            Boot.Run(new Program());
        }
    }
}

4. Run application : Debug/Start Debugging or press F5

preveiw