Пример #1
0
 private void eraseImage(GameObjectImage gmObjImg)
 {
     if (canvas.Children.Contains(gmObjImg.displayImage))
     {
         canvas.Children.Remove(gmObjImg.displayImage);
     }
 }
Пример #2
0
        private void GmObjImg_canDispose(object sender, EventArgs e)
        {
            GameObjectImage gmObjImg = sender as GameObjectImage, tmp;

            while (!display.TryRemove(gmObjImg.gmObj, out tmp))
            {
                ;
            }
            //display.Remove(gmObjImg.gmObj);
        }
Пример #3
0
        //private Task displayImage()
        //{
        //    List<Task> tasks = new List<Task>();
        //    foreach (GameObject gmObj in exist.iterate())
        //    {
        //    GameObjectImage gmObjImg;
        //        if (display.TryGetValue(gmObj, out gmObjImg))
        //        {
        //            gmObjImg = display[gmObj];
        //            Task task = Task.Run(async () =>
        //            {
        //                await Dispatcher.RunAsync(Windows.UI.Core.CoreDispatcherPriority.High, () =>
        //                {
        //                    gmObjImg.animate();
        //                });
        //            });
        //            tasks.Add(task);
        //        }
        //        else
        //        {
        //            Task task = Task.Run(async () =>
        //            {

        //                await Dispatcher.RunAsync(Windows.UI.Core.CoreDispatcherPriority.High, () =>
        //                {
        //                    Image img;
        //                    img = new Image();
        //                    canvas.Children.Add(img);
        //                    gmObjImg = new GameObjectImage(canvas, gmObj, img);
        //                    bool isSafe = display.TryAdd(gmObj, gmObjImg);
        //                    if (false)
        //                    {
        //                        throw new Exception();
        //                    }


        //                    //display[gmObj] = gmObjImg;
        //                });
        //            });
        //            tasks.Add(task);
        //        }
        //    }
        //    foreach (GameObject gmObj in dying.iterate())
        //    {

        //        GameObjectImage gmObjImg = display[gmObj];

        //        Task task = Task.Run(async () =>
        //        {
        //            await Dispatcher.RunAsync(Windows.UI.Core.CoreDispatcherPriority.High, () =>
        //            {
        //                gmObjImg.dying();
        //            });
        //        });
        //        tasks.Add(task);

        //    }
        //    return Task.WhenAll(tasks);
        //}

        private Task displayImage()
        {
            Task task = Task.Run(async() =>
            {
                await Dispatcher.RunAsync(Windows.UI.Core.CoreDispatcherPriority.High, () =>
                {
                    this.keyholder.Focus(FocusState.Keyboard);
                    //Existcount.Text = Existence.getInstance().count.ToString();
                    //Dyingcount.Text = DyingExistence.getInstance().count.ToString();
                    //player.Text = display.Count.ToString();
                    scoreNum.Text = stage.score.ToString();

                    foreach (GameObject gmObj in exist.iterate())
                    {
                        GameObjectImage gmObjImg;
                        if (display.TryGetValue(gmObj, out gmObjImg))
                        {
                            gmObjImg.animate();
                        }
                        else
                        {
                            Image img;
                            img = new Image();
                            canvas.Children.Add(img);
                            gmObjImg             = new GameObjectImage(canvas, gmObj, img);
                            gmObjImg.canDispose += GmObjImg_canDispose;
                            bool isSafe          = display.TryAdd(gmObj, gmObjImg);
                            //display.Add(gmObj, gmObjImg);
                            if (false)
                            {
                                throw new Exception();
                            }
                        }
                    }
                    foreach (GameObject gmObj in dying.iterate())
                    {
                        GameObjectImage gmObjImg;
                        if (display.TryGetValue(gmObj, out gmObjImg))
                        {
                            gmObjImg.dying();
                        }
                    }
                });
            });

            task.Wait();
            return(task);
        }