public async ValueTask Render(GameContext game, Canvas2DContext context)
        {
            if (null == Animation)
            {
                return;
            }

            if (game.GameTime.TotalTime - _lastUpdate > 1000f / Animation.Fps)
            {
                if (_currFrameIndex >= Animation.FramesCount)
                {
                    _completed      = true;
                    _currFrameIndex = 0;
                }

                _lastUpdate    = game.GameTime.TotalTime;
                _currFramePosX = _currFrameIndex * Animation.FrameSize.Width;
                ++_currFrameIndex;
            }

            var dx = -(_transform.Direction.X - 1f) * Animation.FrameSize.Width / 2f;
            await context.SetTransformAsync(_transform.Direction.X, 0, 0, 1, dx, 0);

            await context.DrawImageAsync(Animation.ImageRef, _currFramePosX, 0,
                                         Animation.FrameSize.Width, Animation.FrameSize.Height,
                                         _transform.Position.X, _transform.Position.Y,
                                         Animation.FrameSize.Width, Animation.FrameSize.Height);
        }
Пример #2
0
 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);
 }