public async ValueTask Render(GameContext game, Canvas2DContext context)
        {
            await context.SaveAsync();

            await context.TranslateAsync(_transform.World.Position.X, _transform.World.Position.Y);

            await context.RotateAsync(_transform.World.Rotation);

            await context.DrawImageAsync(Sprite.Source, -Sprite.Origin.X, -Sprite.Origin.Y,
                                         Sprite.Size.Width, Sprite.Size.Height);

            await context.RestoreAsync();
        }
        /// <summary>
        /// 画时针
        /// </summary>
        /// <param name="hour">小时</param>
        /// <param name="radius">半径</param>
        /// <returns></returns>
        private async Task DrawHourHandAsync(int hour, double radius)
        {
            await _context.SaveAsync();

            await _context.TranslateAsync(radius, radius);

            double theta = (hour - 3) * 2 * Math.PI / 12;
            await _context.RotateAsync((float)theta);

            await _context.BeginPathAsync();

            await _context.MoveToAsync(-15, -5);

            await _context.LineToAsync(-15, 5);

            await _context.LineToAsync(radius * 0.6, 1);

            await _context.LineToAsync(radius * 0.6, -1);

            await _context.FillAsync();

            await _context.RestoreAsync();
        }
        public async ValueTask Render(GameContext game, Canvas2DContext context)
        {
            if (null == Animation || !this.Owner.Enabled)
            {
                return;
            }

            await context.SaveAsync();

            await context.TranslateAsync(_transform.World.Position.X + (MirrorVertically ? Animation.FrameSize.Width : 0f), _transform.World.Position.Y);

            await context.RotateAsync(_transform.World.Rotation);

            await context.ScaleAsync(_transform.World.Scale.X *(MirrorVertically ? -1f : 1f), _transform.World.Scale.Y);

            await context.DrawImageAsync(Animation.ImageRef,
                                         _currFramePosX, _currFramePosY,
                                         Animation.FrameSize.Width, Animation.FrameSize.Height,
                                         Animation.HalfFrameSize.Width, Animation.HalfFrameSize.Height,
                                         -Animation.FrameSize.Width, -Animation.FrameSize.Height);

            await context.RestoreAsync();
        }
        public async ValueTask Render(GameContext game, Canvas2DContext context)
        {
            if (!this.Owner.Enabled)
            {
                return;
            }

            await context.SaveAsync();

            await context.TranslateAsync(_transform.World.Position.X, _transform.World.Position.Y);

            await context.RotateAsync(_transform.World.Rotation);

            await context.ScaleAsync(_transform.World.Scale.X, _transform.World.Scale.Y);

            await context.DrawImageAsync(Sprite.ElementRef,
                                         Sprite.Bounds.X, Sprite.Bounds.Y,
                                         Sprite.Bounds.Width, Sprite.Bounds.Height,
                                         Sprite.Origin.X, Sprite.Origin.Y,
                                         -Sprite.Bounds.Width, -Sprite.Bounds.Height);

            await context.RestoreAsync();
        }
Example #5
0
 public void Apply(RotateNode rotateNode)
 {
     _canvas2DContext.RotateAsync(rotateNode.Angle);
 }