Skip to content

Commit

Permalink
Update readme.md
Browse files Browse the repository at this point in the history
  • Loading branch information
mizrael authored Jun 27, 2024
1 parent 2f2b3a5 commit 2c4eddf
Showing 1 changed file with 32 additions and 2 deletions.
34 changes: 32 additions & 2 deletions readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,9 @@ Blazorex can be installed as Nuget package: https://www.nuget.org/packages/Blazo

## Usage

Simply add the `Canvas` Component to your Razor page and register to the `OnCanvasReady` to receive the `CanvasBase` instance.
### Simple scenario

Just add the `Canvas` Component to your Razor page and register to the `OnCanvasReady` to receive the `CanvasBase` instance.

Then use `OnFrameReady` to define your update/render logic:

Expand Down Expand Up @@ -51,6 +53,34 @@ You might also need to update your `index.html` to include the library's CSS:
</head>
```

For a complete sample, check the [./src/Blazorex.Web](./src/Blazorex.Web) folder.
### Multiple Canvases
In case you want to have multiple canvases on the same page, you can use the `CanvasManager` component instead:

```csharp
<CanvasManager @ref="_canvasManager" />

@code{
CanvasManager _canvasManager;

protected override async Task OnAfterRenderAsync(bool firstRender)
{
if (!firstRender)
return;

_canvasManager.CreateCanvas("myCanvas", new CanvasCreationOptions()
{
Width = 800,
Height = 600,
Hidden = false,
OnCanvasReady = this.OnMyCanvasReady,
OnFrameReady = this.OnMyCanvasFrameReady,
});
}
}
```

You simply have to get a reference to the `CanvasManager` and then call the `CreateCanvas` passing an instance of `CanvasCreationOptions` with the desired parameters.

For a complete sample, check the [./src/Blazorex.Web](./src/Blazorex.Samples) folder.

A sample game can be found here: [Blazeroids](https://github.com/mizrael/Blazeroids)

0 comments on commit 2c4eddf

Please sign in to comment.