Skip to content

Commit

Permalink
Merge pull request #2 from mizrael/mousecoords-fix
Browse files Browse the repository at this point in the history
fixed bug with mouse coords not being detected
  • Loading branch information
mizrael authored Sep 5, 2023
2 parents c7b7228 + 422057a commit e38bac4
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 4 deletions.
9 changes: 9 additions & 0 deletions src/Blazorex.Web/Pages/Index.razor
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@
float _x = 400;
float _y = 300;

Blazorex.MouseCoords _mousecoords;

float _dx = 1;
float _dy = 1;
float _spriteSpeed = 0.25f;
Expand Down Expand Up @@ -53,6 +55,7 @@
Height = _height,
OnCanvasReady = this.OnMainCanvasReady,
OnFrameReady = this.OnMainFrameReady,
OnMouseMove = this.OnMainCanvasMouseMove,
});
}

Expand All @@ -79,6 +82,11 @@
this.Render();
}

private void OnMainCanvasMouseMove(Blazorex.MouseCoords coords)
{
_mousecoords = coords;
}

private void Update(float timeStamp)
{
_elapsedTime = timeStamp - _lastUpdate;
Expand Down Expand Up @@ -110,5 +118,6 @@
_context.Font = "24px verdana";
_context.FillStyle = "red";
_context.FillText($"FPS: {fps:###}", 20, 40);
_context.FillText($"Mouse Coords: {_mousecoords.X} : {_mousecoords.Y}", 20, 60);
}
}
2 changes: 1 addition & 1 deletion src/Blazorex/Blazorex.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

<PropertyGroup>
<TargetFramework>net7.0</TargetFramework>
<PackageVersion>1.0.1</PackageVersion>
<PackageVersion>1.0.2</PackageVersion>
<IsPackable>true</IsPackable>
<Authors>davidguida</Authors>
<Product>Blazorex</Product>
Expand Down
6 changes: 3 additions & 3 deletions src/Blazorex/MouseCoords.cs
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
namespace Blazorex
{
public readonly struct MouseCoords
public struct MouseCoords
{
public readonly int X;
public readonly int Y;
public int X { get; set; }
public int Y { get; set; }
}
}

0 comments on commit e38bac4

Please sign in to comment.