Exemplo n.º 1
0
        public void Shoot(string text, int type)
        {
            var line = usableLine();

            if (line == -1)
            {
                clearLine();
                line = usableLine();
            }

            FrameworkElement danmaku = new OutlinedDanmaku(text);

            // Danmaku initilization and display
            if (enableShadowEffect)
            {
                danmaku = new ShadowDanmaku(text);
            }
            //添加emoji类型判断条件 if()
            if (type == 1)
            {
                danmaku = new EmojiDanmaku(text);//text 传path
            }
            danmaku.Margin = new Thickness(0, lineLocationY(line), 0, 0);
            container.Children.Add(danmaku);

            // Initilizing animation
            var anim = new DoubleAnimation();

            anim.From       = this.container.RenderSize.Width;
            anim.To         = -danmaku.DesiredSize.Width - 1600;
            anim.SpeedRatio = danmaku.DesiredSize.Width > 80 ?
                              (.05 * (danmaku.DesiredSize.Width / 1500 + 1)) :
                              (.1 * ((100 - danmaku.DesiredSize.Width) / 100 + 1));
            TranslateTransform trans = new TranslateTransform();

            danmaku.RenderTransform = trans;

            // Handling the end of danmaku
            anim.Completed += new EventHandler(delegate(Object o, EventArgs a) {
                container.Children.Remove(danmaku);
            });

            // Managing the danmaku lines
            var timer = new DispatcherTimer();

            timer.Interval = TimeSpan.FromMilliseconds(300);
            timer.Tick    += new EventHandler(delegate(Object o, EventArgs a) {
                Point relativePoint = danmaku.TransformToAncestor(container)
                                      .Transform(new Point(0, 0));
                if (relativePoint.X < container.ActualWidth - danmaku.DesiredSize.Width - 50)
                {
                    timer.Stop();
                    isOccupy[line] = false;
                }
            });
            timer.Start();

            // Play animation
            trans.BeginAnimation(TranslateTransform.XProperty, anim);
        }
        public void Shoot(string text)
        {
            var line = usableLine();

            if (line == -1) {
                clearLine();
                line = usableLine();
            }

            FrameworkElement danmaku = new OutlinedDanmaku(text);
            // Danmaku initilization and display
            if (enableShadowEffect) {
                danmaku = new ShadowDanmaku(text);
            }

            danmaku.Margin = new Thickness(0, lineLocationY(line), 0, 0);
            container.Children.Add(danmaku);

            // Initilizing animation
            var anim = new DoubleAnimation();
            anim.From = this.container.RenderSize.Width;
            anim.To = -danmaku.DesiredSize.Width - 1600;
            anim.SpeedRatio = danmaku.DesiredSize.Width > 80 ?
                (.05 * (danmaku.DesiredSize.Width / 1500 + 1)) :
                (.1 * ((100 - danmaku.DesiredSize.Width) / 100 + 1));
            TranslateTransform trans = new TranslateTransform();
            danmaku.RenderTransform = trans;

            // Handling the end of danmaku
            anim.Completed += new EventHandler(delegate (Object o, EventArgs a) {
                container.Children.Remove(danmaku);
            });

            // Managing the danmaku lines
            var timer = new DispatcherTimer();
            timer.Interval = TimeSpan.FromMilliseconds(300);
            timer.Tick += new EventHandler(delegate (Object o, EventArgs a) {
                Point relativePoint = danmaku.TransformToAncestor(container)
                          .Transform(new Point(0, 0));
                if (relativePoint.X < container.ActualWidth - danmaku.DesiredSize.Width - 50) {
                    timer.Stop();
                    isOccupy[line] = false;
                }
            });
            timer.Start();

            // Play animation
            trans.BeginAnimation(TranslateTransform.XProperty, anim);
        }