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(); }
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(); }
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(); }
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 void Apply(ScaleNode scaleNode) { _canvas2DContext.ScaleAsync(scaleNode.Factor.X, scaleNode.Factor.Y); }