01. Initializing MELHARFI engine
Welcome to the MELHARFI 2D Game Engine wiki!
Hi guys in this tutorial we are going step by step to discover all features of that engine.
I will make sure to explain in details all posibilities of what we can do, and for that i will use Visual Studio with C# language but you can use VB.Net as well since it work under .NET Framwork 4.0 or higher.
Preference Visual studio 2017 or above, i am using 2019 frensh version for this tutorial.
Application Windows Form (.Net Framework).
Name it 2dProject or anything you want
>Now we need to fix a size for our form, choose what you fit
You have 2 choices either downloading release under release and add MELHARFI.dll manually to references.
Or the easiest way using nuget
Make sure the project is well loaded and no error is found (1) and is referenced (2)
Our representation will be drawn in a Windows Control, meaning that all controls given by your IDE as Form, Panel, even inside a button or picture as long as it's a control object.
But for our case we ar going to use the form itself as placeholder for our drawing shapes, but before we need to explain some details.
It's a class that you should instanciate to handle you game/app contente, you can create more than 1 instance, each one has it's own layers (background, objects, top, control) and are completely isolated.
Now you have to decide WHERE SHOULD I DRAW ?
1- Consider that all the surface of the screen is for the game, in that case you can chose the main form itself as a placeholder for your game, and you only need to create 1 instance.
2- Consider you will use a special surface to draw your game content (First instance of the Manager) maybe a panel inside your form that cover majority of the form or the whole form itself, and another small area "panel" for your hud in foot section of your form (Second instance of your game engine), and anoter area "panel or whatever" for another purpose like a menu in the left side (Third instance of your game engine)
All depend on your game logic and how its complexity, if it's a simple game only one instance of your game engine is sufficient as you just need to know how to deal with the different sections.
If your game is a bit mature or need advanced architecture, you need more than one instance of the Manager instance.
-one instance to draw your game content Non-Static (meaning content is changing all the time when player move or map is changed ...).
-second instance for your hud content Static (the hud usually doesn't change apart some lifepoint could be changed but most of the time it's considered as a second portion of your game), it's usful when you want to clear, modify or remove your screen game (player has changed map) so in this case you don't want to remove your hud, menu and other stuff not considered as a part of your game content, so in this case you don't have to worry about that because hud, menu ... are handled by the other instance of your game engine.
Considering that your main form is suited to your game drawing land.
First you have to chose a resolution suited for you, for exemple let's make it 800x600 (800 pixel for width, 600 pixel for height) we also want it to be fixed, not resizable "FormBorderSyle = FixedSingle", you can manage other stuff like rename the label of the game , the engine does not allow to resize the screen, it only draw item to a control with there original size.
Next step is to create an instance of our game engine "Manager" and for that, go to the code section, right clic on your main form and chose "View Code" or clic F7 shortcut.
You need to add reference of MELHARFI library to you class
using MELHARFI;
using MELHARFI.Manager;
Assuming your game is basic and need only one instance of your game engine add this line in the Form1 class constuctor:
Manager manager = new Manager(this, "name_of_Instance_like_CORE_ENGINE");
The name given to the constructor give a meaning of the current instance, we'll cover its uility later.
By default the background color is black, so if you compile your project you'll see a black window.
To change the background color just add this line
manager.Background = Color.Blue;
And just run your code to see a beautiful window
If you experience some kind of Flickering of screen, it's an issue in GDI+ that you can resolve by adding that peace of code in top of your main form code just after InitializeComponent();
this.SetStyle(ControlStyles.AllPaintingInWmPaint | ControlStyles.UserPaint | ControlStyles.DoubleBuffer, true);
this.Invalidate();
By default the rendering time to screen is refreshed 40 times per second, if by any reason you want to modify that variable, just add this line :
Manager manager = new Manager(this, "CORE_ENGINE");
manager.Background = Color.Blue;
manager.Fps = 60;
That Fps value make sure to update a timer interval inside the Manager game loop to refresh screen using the method Manager.refreshTimer
It's the same as doing :
manager.refreshTimer.Interval = Fps;
Please notice that the Manager is specialy used for dealing with graphic stuff.
You can find many thing around rendering and so and you can discover this using intellisense
Want me to dev an app for you ? dont hesitate to contact me.
Are you looking for a coder/teammate for your project ? Let's give it a try.
Have a proposal for me ? we can discuss about it.
You want to buy me a coffe ? m.elharfi@gmail.com