protected override async ValueTask Render() { await _context.ClearRectAsync(0, 0, this.Display.Size.Width, this.Display.Size.Height); var spriteRenderer = _warrior.Components.Get <AnimatedSpriteRenderComponent>(); await spriteRenderer.Render(this, _context); }
protected override async ValueTask Render() { await _context.ClearRectAsync(0, 0, this.Display.Size.Width, this.Display.Size.Height); var spriteRenderer = _blazorLogo.Components.Get <SpriteRenderComponent>(); await spriteRenderer.Render(_context); }
public void ResetCanvas(Canvas2DContext ctx) { if (spriteService.IsRotated) { ctx.SetTransformAsync(1, 0, 0, 1, 0, 0); } ctx.ClearRectAsync(0, 0, Constants.CanvasSize.Width, Constants.CanvasSize.Height); }
public async ValueTask Step() { var sceneGraph = _game.GetService <SceneGraph>(); await _context.ClearRectAsync(0, 0, _game.Display.Size.Width, _game.Display.Size.Height); await _context.BeginBatchAsync(); await Render(sceneGraph.Root, _game); await _context.EndBatchAsync(); }
internal async Task ClearAsync(Color color) { if (color != Color.White) { await ctx.SetFillStyleAsync(color.AsHtml); await ctx.FillRectAsync(0, 0, this.canvas.Width, this.canvas.Height); } else { await ctx.ClearRectAsync(0, 0, this.canvas.Width, this.canvas.Height); } }
protected override async Task OnAfterRenderAsync(bool firstRender) { _stopwatch.Start(); if (firstRender) { _ctx = await _canvas.CreateCanvas2DAsync(); await _ctx.SetFillStyleAsync("green"); await _ctx.SetStrokeStyleAsync("#777777"); await _ctx.SetLineWidthAsync(1); } await _ctx.ClearRectAsync(0, 0, GridSize *Scale, GridSize *Scale); await _ctx.BeginPathAsync(); for (int i = 0; i <= Scale; ++i) { await _ctx.MoveToAsync(GridSize *i, 0); await _ctx.LineToAsync(GridSize *i, GridSize *Scale); await _ctx.MoveToAsync(0, GridSize *i); await _ctx.LineToAsync(GridSize *Scale, GridSize *i); } for (int y = 0; y < Scale; ++y) { for (int x = 0; x < Scale; ++x) { if (_game.GetState(x, y)) { await _ctx.RectAsync(x *GridSize + 1, y *GridSize + 1, GridSize - 2, GridSize - 2); } } } await _ctx.StrokeAsync(); await _ctx.FillAsync(); _stopwatch.Stop(); RenderCostInMilliSecond = _stopwatch.ElapsedMilliseconds; _stopwatch.Reset(); }
public async Task Init(BECanvasComponent canvas, PainterConfig config) { _config = config ?? throw new ArgumentNullException(nameof(config)); _ = canvas ?? throw new ArgumentNullException(nameof(canvas)); if (_canvas != canvas) { _canvas = canvas; _context = await _canvas.CreateCanvas2DAsync(); } else { await _context.ClearRectAsync(0, 0, _canvas.Width, _canvas.Height); } }
private async ValueTask RenderFrame(SortedList <int, IList <IRenderable> > layers) { await _context.ClearRectAsync(0, 0, _game.Display.Size.Width, _game.Display.Size.Height) .ConfigureAwait(false); await _context.BeginBatchAsync().ConfigureAwait(false); foreach (var layer in layers.Values) { foreach (var renderable in layer) { await renderable.Render(_game, _context).ConfigureAwait(false); } } await _context.EndBatchAsync().ConfigureAwait(false); }
public async ValueTask Render() { await _context.ClearRectAsync(0, 0, _width, _height); await _context.BeginBatchAsync(); await _context.SetFillStyleAsync("white"); await _context.SetFontAsync("32px consolas"); var text = $"Points: {_points.ToString("D3")} High score: {HighScore} {HighScoreName} Lives: {_lives.ToString("D3")}"; var length = await _context.MeasureTextAsync(text); await _context.FillTextAsync(text, _width / 2 - (length.Width / 2), 25); if (GameOver) { await RenderGameOver(); } else if (Won) { await RenderWonGame(); } else if (Started) { await RenderGameFrame(); } else if (!Started) { await _context.SetFillStyleAsync("white"); text = $"Use arrow keys to move, space to fire"; length = await _context.MeasureTextAsync(text); await _context.FillTextAsync(text, _width / 2 - (length.Width / 2), 150); text = $"Press space to start"; length = await _context.MeasureTextAsync(text); await _context.FillTextAsync(text, _width / 2 - (length.Width / 2), 200); } await _context.EndBatchAsync(); }
async ValueTask drawPage(Page p) { await _outputCanvasContext.ClearRectAsync(0, 0, _canvasReference.Width, _canvasReference.Height); await _outputCanvasContext.SetFillStyleAsync("black"); await _outputCanvasContext.FillRectAsync(0, 0, _canvasReference.Width, _canvasReference.Height); for (int i = 0; i < p.elements.Count; i++) { PageElement e = p.elements[i]; await _outputCanvasContext.SetFontAsync(fontCode(e.font)); await _outputCanvasContext.SetFillStyleAsync("#ffffff"); await _outputCanvasContext.FillTextAsync(e.text, e.x *skala, e.y *skala); } await Task.Delay(p.time * 1000); }
public async void GameLoop() { var i = 0; while (i < 1000000) { await Task.Delay(10); await _context.ClearRectAsync(0, 0, _gameWidth, _gameHeight); UpdateGameObjects(); await DrawGameObject(); i++; if (_gameState.Lives <= 0) { i = 1000000; await GameOver(); } } }
private async Task ClearAsync(double radius) { //await _context.MoveToAsync(0, 0); await _context.ClearRectAsync(-radius, -radius, radius * 2, radius * 2); }
private async Task ClearCanvasAsync() { await _canvas2DContext.ClearRectAsync(0, 0, CanvasWidth, CanvasHeight); ResetState(); }
private async Task BuildCanvas() { if (context == null) { context = await canvasReference.CreateCanvas2DAsync(); await context.SetTextAlignAsync(TextAlign.Center); await context.SetTextBaselineAsync(TextBaseline.Middle); } await context.ClearRectAsync(0, 0, 150, 150); if (loading) { await context.FillTextAsync("Loading...", 75, 75); return; } Point drawPosition; if (character.HairBelowBody != null) { drawPosition = CalculateDrawPosition(character.HairBelowBodyPosition, character.HairBelowBody); await context.DrawImageAsync(HairBelowBodyRef, drawPosition.X, drawPosition.Y); } drawPosition = CalculateDrawPosition(character.BodyPosition, character.Body); await context.DrawImageAsync(BodyRef, drawPosition.X, drawPosition.Y); if (character.Mail != null) { drawPosition = CalculateDrawPosition(character.MailPosition, character.Mail); await context.DrawImageAsync(MailRef, drawPosition.X, drawPosition.Y); } drawPosition = CalculateDrawPosition(character.HeadPosition, character.Head); await context.DrawImageAsync(HeadRef, drawPosition.X, drawPosition.Y); if (character.EarType != EarType.Normal) { drawPosition = CalculateDrawPosition(character.EarPosition, character.Ear); await context.DrawImageAsync(EarRef, drawPosition.X, drawPosition.Y); } if (character.HasFace) { drawPosition = CalculateDrawPosition(character.FacePosition, character.Face); await context.DrawImageAsync(FaceRef, drawPosition.X, drawPosition.Y); } if (character.Hair != null) { drawPosition = CalculateDrawPosition(character.HairPosition, character.Hair); await context.DrawImageAsync(HairRef, drawPosition.X, drawPosition.Y); } if (character.HairOverHead != null) { drawPosition = CalculateDrawPosition(character.HairOverHeadPosition, character.HairOverHead); await context.DrawImageAsync(HairOverHeadRef, drawPosition.X, drawPosition.Y); } if (character.BackHair != null) { drawPosition = CalculateDrawPosition(character.BackHairPosition, character.BackHair); await context.DrawImageAsync(BackHairRef, drawPosition.X, drawPosition.Y); } if (character.BackHairBelowCap != null) { drawPosition = CalculateDrawPosition(character.BackHairBelowCapPosition, character.BackHairBelowCap); await context.DrawImageAsync(BackHairBelowCapRef, drawPosition.X, drawPosition.Y); } if (character.Pants != null) { drawPosition = CalculateDrawPosition(character.PantsPosition, character.Pants); await context.DrawImageAsync(PantsRef, drawPosition.X, drawPosition.Y); } if (character.Arm != null) { drawPosition = CalculateDrawPosition(character.ArmPosition, character.Arm); await context.DrawImageAsync(ArmRef, drawPosition.X, drawPosition.Y); } if (character.Hand != null) { drawPosition = CalculateDrawPosition(character.HandPosition, character.Hand); await context.DrawImageAsync(HandRef, drawPosition.X, drawPosition.Y); } if (character.MailArm != null) { drawPosition = CalculateDrawPosition(character.MailArmPosition, character.MailArm); await context.DrawImageAsync(MailArmRef, drawPosition.X, drawPosition.Y); } }
public Task Clear(int x, int y, int width, int height) => _canvas2DContext.ClearRectAsync(x, y, width, height);
protected override async ValueTask Render() { await _context.ClearRectAsync(0, 0, this.Display.Size.Width, this.Display.Size.Height); await Render(_sceneGraph.Root); }