コード例 #1
0
        public async ValueTask Render(GameContext game, Canvas2DContext context)
        {
            if (null == Animation)
            {
                return;
            }

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

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

            await context.SaveAsync();

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

            await context.ScaleAsync(MirrorVertically? -1f : 1f, 1f);

            await context.DrawImageAsync(Animation.ImageRef,
                                         _currFramePosX, 0,
                                         Animation.FrameSize.Width, Animation.FrameSize.Height,
                                         0, 0,
                                         Animation.FrameSize.Width, Animation.FrameSize.Height);

            await context.RestoreAsync();
        }
コード例 #2
0
        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();
        }
コード例 #3
0
        public async ValueTask Render(GameContext game, Canvas2DContext context)
        {
            if (!this.Owner.Enabled || this.Hidden)
            {
                return;
            }

            var y = game.Display.Size.Height - bottomMargin;

            await context.SaveAsync();

            await context.TranslateAsync(leftMargin, y);

            await RenderHearts(game, context);
            await RenderInventory(game, context);

            await context.RestoreAsync();
        }
コード例 #4
0
        public async ValueTask Render(GameContext game, Canvas2DContext context)
        {
            if (null == Animation)
            {
                return;
            }

            if (game.GameTime.TotalMilliseconds - _lastUpdate > 1000f / Animation.Fps)
            {
                _lastUpdate = game.GameTime.TotalMilliseconds;

                _currFramePosX += Animation.FrameSize.Width;
                if (_currFramePosX >= Animation.ImageSize.Width)
                {
                    _currFramePosX  = 0;
                    _currFramePosY += Animation.FrameSize.Height;
                }

                if (_currFramePosY >= Animation.ImageSize.Height)
                {
                    _currFramePosY = 0;
                }

                _currFrameIndex++;
                if (_currFrameIndex >= Animation.FramesCount)
                {
                    _currFrameIndex = _currFramePosX = _currFramePosY = 0;
                }
            }

            await context.SaveAsync();

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

            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,
                                         0, 0,
                                         Animation.FrameSize.Width, Animation.FrameSize.Height);

            await context.RestoreAsync();
        }
コード例 #5
0
        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();
        }
コード例 #6
0
        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();
        }
コード例 #7
0
        /// <summary>
        /// 画表盘圆
        ///</summary>
        ///<param name="strokeStyle"></param>
        ///<param name="radius">半径</param>
        ///<param name="fillStyle">填充色</param>
        /// <returns></returns>
        private async Task DrawCicleAsync(string strokeStyle, double radius, string fillStyle)
        {
            await _context.SaveAsync();

            await _context.TranslateAsync(radius, radius);

            await _context.BeginPathAsync();

            await _context.SetStrokeStyleAsync(strokeStyle);

            await _context.ArcAsync(0, 0, radius, 0, 2 *Math.PI, true);

            await _context.SetFillStyleAsync(fillStyle);

            await _context.FillAsync();

            await _context.RestoreAsync();
        }
コード例 #8
0
 public void Push()
 {
     _canvas2DContext.SaveAsync();
 }