Simple Program - sinusinu/Flora GitHub Wiki

Let's write a simple program using Flora!

In wiki documentations, example project is using the namespace FloraTest. Change that if you are copy-pasting into different project.

Program.cs

Change existing Program.cs code to this:

using Flora;

namespace FloraTest {
    class Program {
        static void Main(string[] args) {
            FloraConfig config = new FloraConfig();
            MyCore core = new MyCore();
            new FloraApplication(core, config);
        }
    }
}

With using Flora, we use:

  • FloraConfig
    • Contains launch configuration for this app. For now we are using default values.
  • MyCore
    • We will take a look at this shortly after.
  • new FloraApplication(core, config)
    • Starts the application with given FloraCore and FloraConfig.

MyCore.cs

Create a new class file named MyCore.cs. Fill it with this:

using Flora;
using Flora.Gfx;

namespace FloraTest {
    class MyCore : FloraCore {
        public override void Prepare() {
            
        }

        public override void Pause() {
            
        }

        public override void Resume() {
            
        }

        public override void Resize(int width, int height) {
            
        }

        public override void Render(float delta) {
            Gfx.Begin();
            Gfx.End();
        }

        public override void Cleanup() {
            
        }
    }
}

MyCore inherits FloraCore, which provide functions that works as the main logic of your application. FloraCore provides 6 functions you can override:

  • Prepare()
    • This function is called when your core is being created. Difference between the constructor and Prepare() is that in Prepare(), Flora is guaranteed to be already initialized - so you can use functions of Flora to prepare "Flora things" e.g. Texture or Music.
  • Pause()
    • This function is called when your app loses focus.
  • Resume()
    • This function is called when your app gains focus.
  • Resize(int width, int height)
    • This function is called when your app resizes.
  • Render(float delta)
    • This function is called when the "main loop" of your game logic and screen drawing routines should be executed.
    • Gfx.Begin() and Gfx.End() are required to draw anything, but does nothing by itselves. Leave it as is for now.
  • Cleanup()
    • This function is called when your app should clean up.

Since there is no code to execute, this code will show an empty window. Try running it!