Difference between revisions of "GeonBit Class Example"
(→Creating a Base Class) |
|||
Line 21: | Line 21: | ||
<syntaxhighlight lang=csharp> | <syntaxhighlight lang=csharp> | ||
+ | using Microsoft.Xna.Framework; | ||
+ | using GeonBit.UI; | ||
+ | using GeonBit.UI.Entities; | ||
+ | |||
class UIScreen | class UIScreen | ||
{ | { | ||
Line 30: | Line 34: | ||
<syntaxhighlight lang=csharp> | <syntaxhighlight lang=csharp> | ||
+ | using Microsoft.Xna.Framework; | ||
+ | using GeonBit.UI; | ||
+ | using GeonBit.UI.Entities; | ||
+ | |||
class UIScreen | class UIScreen | ||
{ | { | ||
Line 44: | Line 52: | ||
<syntaxhighlight lang=csharp> | <syntaxhighlight lang=csharp> | ||
+ | using Microsoft.Xna.Framework; | ||
+ | using GeonBit.UI; | ||
+ | using GeonBit.UI.Entities; | ||
+ | |||
class UIScreen | class UIScreen | ||
{ | { |
Revision as of 11:18, 13 October 2017
Creating a Base Class
The first step is to create a base class which will be inherited by each interface screen.
With a project open, click project and add new class. A suitable name should be used (eg UI, UIScreen etc) it will create your class:
class UIScreen
{
}
Add the following to the using section of the class:
using Microsoft.Xna.Framework;
using GeonBit.UI;
using GeonBit.UI.Entities;
Within the curly brackets you should create a public Panel , this will be what the user will see.
using Microsoft.Xna.Framework;
using GeonBit.UI;
using GeonBit.UI.Entities;
class UIScreen
{
public Panel window;
}
A constructor method is called the same name as the class, and is normally public:
using Microsoft.Xna.Framework;
using GeonBit.UI;
using GeonBit.UI.Entities;
class UIScreen
{
public Panel window;
public UIScreen()
{
}
}
Now we need to add the code to create the window panel and add it to the interface:
using Microsoft.Xna.Framework;
using GeonBit.UI;
using GeonBit.UI.Entities;
class UIScreen
{
public Panel window;
public UIScreen()
{
window = new Panel(new Vector2(300, 300), PanelSkin.Default, Anchor.Center);
UserInterface.Active.AddEntity(window);
}
}
The vector2 sets the size of the window, panelskin has several options to change the appearence, anchor will position the panel and again many other options are available.
Create a Screen Class
Create a new class as before and call it screen (or menu, gameover etc).
class Screen {
} </syntaxhighlight>
Add the following to the using section of the class:
using Microsoft.Xna.Framework;
using GeonBit.UI;
using GeonBit.UI.Entities;
You need to say it is a class of your base class so add:
class Screen:UIScreen
{
}