I am trying to animate a circle svg with Blazor. I have seen this done with the Tetris game so it should be possible i just cant figure out how to get it working.
<svg width="600" height="400">
<Ball Height="@Ball.Height" Width="@Ball.Width" CurrentPosition="@Ball.CurrentPosition"></Ball>
</svg>
<button class="btn btn-primary" @onclick="@Bounce">bounce</button>
Component
@inherits BallModel;
@using Blong.Client.Model
<circle cx="@CurrentPosition.X" cy="@CurrentPosition.Y" r="@Radius" style="@Style" />
bounce code
void Bounce()
{
for (int i = 0; i < 1000; i++)
{
Task.Run(() => SetPosition(Ball.CurrentPosition.X, Ball.CurrentPosition.Y++, GameHeight));
}
}
public async Task<bool> SetPosition(int x, int y, int LastRow)
{
if (y <= LastRow)
{
Ball.CurrentPosition.Y++;
Thread.Sleep(500);
return true;
}
return false;
}
This does kind of work. Every time i push the button my ball hops to the new position. Is there some way to get this to reload as it goes though the loop? I am trying to see my ball moving around the screen.