-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
8 changed files
with
199 additions
and
140 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
# Drawing Your First Sprite | ||
|
||
## Preloading Your Sprite | ||
|
||
|
||
## Retrieving Your Sprite | ||
|
||
|
||
## Drawing Your Sprite | ||
|
||
|
||
## Moving, Squishing, Spinning, Stretching | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,135 @@ | ||
# Getting started | ||
|
||
> [!WARNING] | ||
> This documentation is currently out-of-date! | ||
> This will be resolved ASAP. To some degree this might still work for you. | ||
> Do make sure to take a look at the [Example Project](https://github.com/Naamloos/Axolotl2D/tree/master/Axolotl2D.Example) | ||
|
||
To create a new Axolotl2D game, you'll want to reference the Axolotl2D library and create a new class inheriting the abstract `Game` class. This is very much prone to changes and may or may not be outdated at the time of reading! Once Axolotl2D is more ready for "general use", a proper documentation will be written. | ||
|
||
```cs | ||
using System.Numerics; | ||
using Microsoft.Extensions.Logging; | ||
using Axolotl2D.Drawable; | ||
using Axolotl2D.Entities; | ||
using Axolotl2D.Input; | ||
|
||
public class MyGame : Game | ||
{ | ||
// Our services | ||
private Mouse? _mouse; | ||
private ILogger<ExampleGame> _logger; | ||
|
||
// Our resources / drawables | ||
private Sprite? _sprite; | ||
|
||
// You are required to pass the IServiceProvider service as a | ||
// dependency to the base Game class. | ||
// Other things like the Mouse, or the ILogger<MyGame> are free to | ||
// inject as needed, if they're defined in your services. | ||
// You are also able to set the max framerate and max update rate | ||
// through the base constructor. | ||
// These will later be changeable at runtime, but for the time being | ||
// these can only be updated as your game gets constructed. | ||
public ExampleGame(IServiceProvider services, Mouse mouse, | ||
ILogger<MyGame> logger) | ||
: base(services, maxDrawRate: 240, maxUpdateRate: 240) | ||
{ | ||
// Set a title for the window | ||
Title = "Axolotl2D Game"; | ||
// Set a clear color | ||
ClearColor = Color.FromHTML("#0088FF"); | ||
// These can be changed at any time in your game loop. | ||
// Axolotl2D uses events for it's game loop. You'll want to hook | ||
// these manually as you see fit. | ||
OnLoad += Load; | ||
OnUpdate += Update; | ||
OnDraw += Draw; | ||
OnResize += Resize; | ||
|
||
// Assigning properties from dependencies as needed. | ||
this._logger = logger; | ||
this._mouse = mouse; | ||
} | ||
|
||
// This is the place where you would pre-load all your assets. | ||
public void Load() | ||
{ | ||
// We can load sprites from embedded resources. | ||
// You'll have to mark your texture as an Embedded Resource | ||
_sprite = Sprite.FromManifestResource(this, | ||
"MyAwesomeGame.Sprites.MySprite.png"); | ||
// Of course, it is also possible to load a Sprite from any other | ||
// type of Stream. | ||
// This is done with Sprites constructor: | ||
// _sprite = new Sprite(this, imageStream); | ||
_logger.LogInformation("Loaded Game Assets"); | ||
} | ||
|
||
// This is our draw method. You'll want to draw your sprites here. | ||
public void Draw(double frameDelta, double frameRate) | ||
{ | ||
// This will draw your sprite at coordinates 50, 50 | ||
// with a size of 50x50 | ||
_sprite.Draw(50, 50, 50, 50); | ||
} | ||
|
||
// This is our update method. We can use this method to | ||
// update values without interrupting our draw loop. | ||
// For example, you'll want to manipulate your Sprite's | ||
// position and size here. | ||
public void Update(double frameDelta) | ||
{ | ||
|
||
} | ||
|
||
// This is the Resize method. | ||
// It is called when the game window resizes. | ||
public void Resize(Vector2D<int> size) | ||
{ | ||
} | ||
|
||
// When your game is closed, | ||
// you'll want to clean up everything nicely. | ||
// This can be done right here. | ||
public override void Cleanup() | ||
{ | ||
_logger.LogInformation("Cleaned up events and unloading game..."); | ||
// unhook events | ||
OnLoad -= Load; | ||
OnUpdate -= Update; | ||
OnDraw -= Draw; | ||
OnResize -= Resize; | ||
} | ||
} | ||
``` | ||
|
||
Once you're done creating your Game class, you'll want to create a Host that houses your game and injects dependencies where you need them. | ||
You'll want to do this in your Program.cs. | ||
|
||
```cs | ||
using Microsoft.Extensions.Hosting; | ||
using Microsoft.Extensions.DependencyInjection; | ||
using Axolotl2D; | ||
|
||
internal class Program | ||
{ | ||
static void Main(string[] args) | ||
{ | ||
var host = Host.CreateDefaultBuilder(args) | ||
.ConfigureServices((hostContext, services) => | ||
{ | ||
services.AddGame<ExampleGame>(); | ||
services.UseMouse(); | ||
services.AddLogging(); | ||
}) | ||
.Build(); | ||
|
||
host.Start(); | ||
} | ||
} | ||
``` | ||
As of right now, the engine is very barebones. More to come in the near future! |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,135 +1,20 @@ | ||
# Getting started | ||
# Getting Started with Axolotl2D | ||
|
||
> [!WARNING] | ||
> This documentation is currently out-of-date! | ||
> This will be resolved ASAP. To some degree this might still work for you. | ||
> Do make sure to take a look at the [Example Project](https://github.com/Naamloos/Axolotl2D/tree/master/Axolotl2D.Example) | ||
*[Old article](./getting-started-old.md)* | ||
|
||
To get started working with Axolotl2D, you will first need to set up your project. This guide will walk you through the necessary steps to configure your project, and run a simple example to ensure everything is working correctly. By the end of this guide, you should be ready to start developing your own projects. | ||
|
||
To create a new Axolotl2D game, you'll want to reference the Axolotl2D library and create a new class inheriting the abstract `Game` class. This is very much prone to changes and may or may not be outdated at the time of reading! Once Axolotl2D is more ready for "general use", a proper documentation will be written. | ||
## Creating a new project | ||
// TODO | ||
|
||
```cs | ||
using System.Numerics; | ||
using Microsoft.Extensions.Logging; | ||
using Axolotl2D.Drawable; | ||
using Axolotl2D.Entities; | ||
using Axolotl2D.Input; | ||
## Creating a GenericHost | ||
// TODO | ||
|
||
public class MyGame : Game | ||
{ | ||
// Our services | ||
private Mouse? _mouse; | ||
private ILogger<ExampleGame> _logger; | ||
## Creating your game skeleton | ||
// TODO | ||
|
||
// Our resources / drawables | ||
private Sprite? _sprite; | ||
## Registering your game and services into the host | ||
// TODO | ||
|
||
// You are required to pass the IServiceProvider service as a | ||
// dependency to the base Game class. | ||
// Other things like the Mouse, or the ILogger<MyGame> are free to | ||
// inject as needed, if they're defined in your services. | ||
// You are also able to set the max framerate and max update rate | ||
// through the base constructor. | ||
// These will later be changeable at runtime, but for the time being | ||
// these can only be updated as your game gets constructed. | ||
public ExampleGame(IServiceProvider services, Mouse mouse, | ||
ILogger<MyGame> logger) | ||
: base(services, maxDrawRate: 240, maxUpdateRate: 240) | ||
{ | ||
// Set a title for the window | ||
Title = "Axolotl2D Game"; | ||
// Set a clear color | ||
ClearColor = Color.FromHTML("#0088FF"); | ||
// These can be changed at any time in your game loop. | ||
// Axolotl2D uses events for it's game loop. You'll want to hook | ||
// these manually as you see fit. | ||
OnLoad += Load; | ||
OnUpdate += Update; | ||
OnDraw += Draw; | ||
OnResize += Resize; | ||
|
||
// Assigning properties from dependencies as needed. | ||
this._logger = logger; | ||
this._mouse = mouse; | ||
} | ||
|
||
// This is the place where you would pre-load all your assets. | ||
public void Load() | ||
{ | ||
// We can load sprites from embedded resources. | ||
// You'll have to mark your texture as an Embedded Resource | ||
_sprite = Sprite.FromManifestResource(this, | ||
"MyAwesomeGame.Sprites.MySprite.png"); | ||
// Of course, it is also possible to load a Sprite from any other | ||
// type of Stream. | ||
// This is done with Sprites constructor: | ||
// _sprite = new Sprite(this, imageStream); | ||
_logger.LogInformation("Loaded Game Assets"); | ||
} | ||
|
||
// This is our draw method. You'll want to draw your sprites here. | ||
public void Draw(double frameDelta, double frameRate) | ||
{ | ||
// This will draw your sprite at coordinates 50, 50 | ||
// with a size of 50x50 | ||
_sprite.Draw(50, 50, 50, 50); | ||
} | ||
|
||
// This is our update method. We can use this method to | ||
// update values without interrupting our draw loop. | ||
// For example, you'll want to manipulate your Sprite's | ||
// position and size here. | ||
public void Update(double frameDelta) | ||
{ | ||
|
||
} | ||
|
||
// This is the Resize method. | ||
// It is called when the game window resizes. | ||
public void Resize(Vector2D<int> size) | ||
{ | ||
} | ||
|
||
// When your game is closed, | ||
// you'll want to clean up everything nicely. | ||
// This can be done right here. | ||
public override void Cleanup() | ||
{ | ||
_logger.LogInformation("Cleaned up events and unloading game..."); | ||
// unhook events | ||
OnLoad -= Load; | ||
OnUpdate -= Update; | ||
OnDraw -= Draw; | ||
OnResize -= Resize; | ||
} | ||
} | ||
``` | ||
|
||
Once you're done creating your Game class, you'll want to create a Host that houses your game and injects dependencies where you need them. | ||
You'll want to do this in your Program.cs. | ||
|
||
```cs | ||
using Microsoft.Extensions.Hosting; | ||
using Microsoft.Extensions.DependencyInjection; | ||
using Axolotl2D; | ||
|
||
internal class Program | ||
{ | ||
static void Main(string[] args) | ||
{ | ||
var host = Host.CreateDefaultBuilder(args) | ||
.ConfigureServices((hostContext, services) => | ||
{ | ||
services.AddGame<ExampleGame>(); | ||
services.UseMouse(); | ||
services.AddLogging(); | ||
}) | ||
.Build(); | ||
|
||
host.Start(); | ||
} | ||
} | ||
``` | ||
As of right now, the engine is very barebones. More to come in the near future! | ||
## Initializing and running your game | ||
// TODO |
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,4 @@ | ||
- name: Getting Started | ||
href: getting-started.md | ||
href: getting-started.md | ||
- name: Drawing Your First Sprite | ||
href: drawing-your-first-sprite.md |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.