private async void Button_Click(object sender, RoutedEventArgs e) { try { var file = await Package.Current.InstalledLocation.GetFileAsync($"{_stickers[index]}.tgs"); var result = await file.CopyAsync(ApplicationData.Current.LocalFolder, file.Name, NameCollisionOption.ReplaceExisting); } catch { } using (var lottie = CachedAnimation.LoadFromFile(ApplicationData.Current.LocalFolder.Path + $"\\{_stickers[index]}.tgs", false, true, null)) { Pic.Source = lottie.RenderSync(0, 256, 256); } //var player = new LottieView //{ // Width = 200, // Height = 200, // Source = new Uri($"ms-appdata://local/{_stickers[index]}.tgs") //}; //Panel.Children.Add(player); //index = (index + 1) % _stickers.Length; }
private IAnimation LoadFromFile(string path, bool cache) { if (cache) { return(CachedAnimation.LoadFromFile(path, true, _limitFps)); } return(Animation.LoadFromFile(path)); }
private void Move(float elapseSeconds) { float h = Input.GetAxisRaw("Horizontal"); float v = Input.GetAxisRaw("Vertical"); CachedAnimation.SetFloat("H", h); CachedAnimation.SetFloat("V", v); if (Math.Abs(h) > Math.Abs(v)) { collider(Vector2.right, Mathf.Sign(h), CachedTransform.position.y % 1, elapseSeconds); } else if (Math.Abs(v) > Math.Abs(h)) { collider(Vector2.up, Mathf.Sign(v), CachedTransform.position.x % 1, elapseSeconds); } }
private void OnUnloaded(object sender, RoutedEventArgs e) { Subscribe(false); _canvas.CreateResources -= OnCreateResources; _canvas.Draw -= OnDraw; _canvas.Unloaded -= OnUnloaded; _canvas.RemoveFromVisualTree(); _canvas = null; Dispose(); //_animation?.Dispose(); _animation = null; _bitmap?.Dispose(); _bitmap = null; }
private void OnSourceChanged(string newValue, string oldValue) { var canvas = _canvas; if (canvas == null) { return; } if (newValue == null) { //canvas.Paused = true; //canvas.ResetElapsedTime(); Subscribe(false); Dispose(); return; } if (string.Equals(newValue, oldValue, StringComparison.OrdinalIgnoreCase) || string.Equals(newValue, _source, StringComparison.OrdinalIgnoreCase)) { return; } var animation = CachedAnimation.LoadFromFile(newValue, _isCachingEnabled, _limitFps, ColorReplacements); if (animation == null) { // The app can't access the file specified return; } _source = newValue; _animation = animation; _animationIsCached = !animation.ShouldCache; _animationFrameRate = animation.FrameRate; _animationTotalFrame = animation.TotalFrame; _index = _isCachingEnabled ? 0 : _animationTotalFrame - 1; var update = TimeSpan.FromSeconds(_animation.Duration / _animation.TotalFrame); if (_limitFps && _animation.FrameRate >= 60) { update = TimeSpan.FromSeconds(update.TotalSeconds * 2); } //canvas.Paused = true; //canvas.ResetElapsedTime(); //canvas.TargetElapsedTime = update > TimeSpan.Zero ? update : TimeSpan.MaxValue; if (AutoPlay || _shouldPlay) { _shouldPlay = false; Subscribe(true); //canvas.Paused = false; } else { Subscribe(false); // Invalidate to render the first frame Invalidate(); _canvas.Invalidate(); } }