Esempio n. 1
0
        public void Play(GUIStage firstStage, int maxFPS = 30)
        {
            LoadStage(firstStage);
            this.Show();
            Graphics frontFrame    = Graphics.FromHwnd(this.Handle);
            DateTime lastFrameTime = DateTime.Now;
            double   timePerFrame  = 1000 / maxFPS;

            while (true)
            {
                if (!this.Created)
                {
                    break;
                }
                if (NextStage != null)
                {
                    CurrentStage = NextStage;
                    NextStage    = null;
                    CurrentStage.Start();
                }

                float dt = (float)(DateTime.Now - lastFrameTime).TotalSeconds;
                lastFrameTime = DateTime.Now;

                CurrentStage.Update(dt);
                CurrentStage.ClearBackFrame();
                CurrentStage.Render();
                CurrentStage.PasteToFrontBuffor(frontFrame, new Rectangle(0, 0, this.ClientSize.Width, this.ClientSize.Height));


                Application.DoEvents();
                double pause = timePerFrame - (DateTime.Now - lastFrameTime).TotalMilliseconds;
                if (pause > 0)
                {
                    System.Threading.Thread.Sleep((int)pause);
                }
            }
        }
Esempio n. 2
0
 public static void LoadStage(GUIStage newStage)
 {
     NextStage = newStage;
 }