Menu scene
We will start this demo from a fresh project that you can find in the StartFiles
folder. This project already contains all the assets and a basic folder setup that will help us organize our game files.
We will create a simple menu with two buttons, one to start the game and another one to exit the game. Let's start by creating a new class called MenuScene
that inherits from GameScene
.
public class MenuScene :GameScene
Fields
Our class will have four fields: a background, two buttons, and a SoundEffect
class.
private GameSprite _background; private GameButton _startButton; private GameButton _exitButton; private Song _backgroundMusic;
Constructor
The constructor remains empty but we need to pass the name of this scene to the base class.
public MenuScene():base("Menu"){}
Initialize
In this method, we will initialize the background and the buttons. The PivotPoint
property of the buttons is set at the top-middle; this will make it easy to position them on the middle of the screen. We also add...