FosterFramework.Extensions.Scenes 0.0.9-alpha

This is a prerelease version of FosterFramework.Extensions.Scenes.
dotnet add package FosterFramework.Extensions.Scenes --version 0.0.9-alpha                
NuGet\Install-Package FosterFramework.Extensions.Scenes -Version 0.0.9-alpha                
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="FosterFramework.Extensions.Scenes" Version="0.0.9-alpha" />                
For projects that support PackageReference, copy this XML node into the project file to reference the package.
paket add FosterFramework.Extensions.Scenes --version 0.0.9-alpha                
#r "nuget: FosterFramework.Extensions.Scenes, 0.0.9-alpha"                
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
// Install FosterFramework.Extensions.Scenes as a Cake Addin
#addin nuget:?package=FosterFramework.Extensions.Scenes&version=0.0.9-alpha&prerelease

// Install FosterFramework.Extensions.Scenes as a Cake Tool
#tool nuget:?package=FosterFramework.Extensions.Scenes&version=0.0.9-alpha&prerelease                

<p align="center"> This repository contains the <strong>FosterFramework.Extensions.Scenes</strong> source code. </p>

<p align="center"> <a href="#introduction">Introduction</a>  •  <a href="#installation">Installation</a>  •  <a href="#usage">Usage</a>  •  <a href="#documentation">Documentation</a>  •  <a href="#samples">Samples</a> </p>

Introduction

This FosterFramework.Extensions.Scenes library provides simple api to implements scenes managment in your FosterFramework game.

Installation

Nuget
dotnet add package FosterFramework.Extensions.Scenes
Include project
  • Clone the project git clone https://github.com/mc-lep/Foster.Extensions.Scenes.git
  • Add a reference to the cloned project

Usage

Sample code that shows how to use the library:

ScenesManager scenesManager = new();
scenesManager.SwitchToScene(new Scene1()); 

The other available methods are described in the next section.

Documentation

To use the library, you must follow these three steps

1. Create a Scene

A scene is just a class which will be updated and rendered at each frame. It's supposed to have all the logic of a GameState of your game (ex: Setting, Title screen, Gameplay, ...)

To create a scene just inihirit from the base Scene class and implements the Update and Render methods.

internal class TitleScene : Scene
{
    public static readonly string FontsPath = Path.Combine("Content", "Fonts");
    public static readonly SpriteFont _titleFont = new(Path.Combine(FontsPath, "Poppins-Black.ttf"), 38);

    public string Title { get; }
    public Vector2 TitlePosition { get; }

    public TitleScene(string title, string message)
    {
        Title = title;
        TitlePosition = new Vector2((App.Width - _titleFont.WidthOfLine(Title)) * 0.5f, App.Height * 0.5f - _titleFont.HeightOf(Title));
    }

    public override void Render()
    {
        Graphics.Clear(Color.Black);

        Batch.Text(_titleFont, Title, TitlePosition, Color.White);
        
        Batch.Render();
        Batch.Clear();
    }
}

2. Initialize scene manager

Impletent a new Game Module and initialize a ScenesManager.

internal class GameRoot : Module
{
    private readonly ScenesManager _scenesManager = new();

    public override void Update()
    {
        _scenesManager.Update();
    }

    public override void Render()
    {
        _scenesManager.Render();
    }
}

3. Show you scene

Call the method SwitchToScene, and the ScenesManager will update and render your scene at each frame.

internal class GameRoot : Module
{
    private readonly ScenesManager _scenesManager = new();

    public override void Startup()
    {
        _scenesManager.SwitchToScene(new TitleScene()); // Swicth to your scene
    }

    public override void Update()
    {
        _scenesManager.Update();
    }

    public override void Render()
    {
        _scenesManager.Render();
    }
}

You can add transitions when switching to your scene by passing a transition object in method SwitchToScene

public override void Startup()
{
	_scenesManager.SwitchToScene(new TitleScene(), new ColorFadeTransition(Color.White, 1f, Ease.QuadOut)); // Swicth to your scene using a transition
}

Included transitions
  • ColorFadeTransition : Blend your screen to a Color and then the next screen from this Color

Samples

A samples project is included in the repository, you can found it here

Product Compatible and additional computed target framework versions.
.NET net8.0 is compatible.  net8.0-android was computed.  net8.0-browser was computed.  net8.0-ios was computed.  net8.0-maccatalyst was computed.  net8.0-macos was computed.  net8.0-tvos was computed.  net8.0-windows was computed. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.

NuGet packages

This package is not used by any NuGet packages.

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last updated
0.0.9-alpha 110 1/15/2024
0.0.8-alpha 102 12/28/2023