Example #1
0
        public void Update()
        {
            //start the timer to measure the frame rendering time
            timer.Start();

            //get the system events(suspend, shut down etc)
            SystemEvents.CheckEvents();

            //set up GL instance
            Sce.PlayStation.HighLevel.GameEngine2D.Director.Instance.GL.SetBlendMode(Sce.PlayStation.HighLevel.GameEngine2D.Base.BlendMode.Normal);
            //update the Director
            Sce.PlayStation.HighLevel.GameEngine2D.Director.Instance.Update();

            //set the additional framebuffer to render to
            Sce.PlayStation.HighLevel.GameEngine2D.Director.Instance.GL.Context.SetFrameBuffer(offscreenBuffer);

            //set the viewport to the size of the offscreen framebuffer
            Sce.PlayStation.HighLevel.GameEngine2D.Director.Instance.GL.Context.SetViewport(0, 0, 960, 544);
            //render the scene to the framebuffer
            Sce.PlayStation.HighLevel.GameEngine2D.Director.Instance.CurrentScene.render();


            //switch to the default framebuffer again
            Sce.PlayStation.HighLevel.GameEngine2D.Director.Instance.GL.Context.SetFrameBuffer(null);

            //set the viewport to the size of the device again
            Sce.PlayStation.HighLevel.GameEngine2D.Director.Instance.GL.Context.SetViewport(0, 0, GraphicsContext.ScreenSizes [0].Width, GraphicsContext.ScreenSizes [0].Height);

            //draw the offscreen framebuffer on the actual screen
            offscreenSprite.Draw();



            //render UI
            //UISystem.Update(Touch.GetData(0));
            //UISystem.Render();


            //DEBUG
            //offscreenSprite.DebugDrawContentLocalBounds();

            //stop the timer,calculate the time per frame
            timer.Stop();
            long ms = timer.ElapsedMilliseconds;


            //sleep to limit the FPS to 30
            if (ms < 33)
            {
                Thread.Sleep((int)(33 - ms));
                ms += (33 - ms);
            }

            //calculate the number of FPS and send to console
            int fps = (int)(1000 / ms);

            //System.Console.WriteLine ("fps: {0}", fps);
            //System.Console.WriteLine ("Memory in use in KBytes: " + System.GC.GetTotalMemory (true) / 1024);

            //if (Game.Instance != null && Game.Instance.ammoList != null)
            //	System.Console.WriteLine ("Number of enemies in the list: {0} ", Game.Instance.bulletList.Count);

            //reset the timer again
            timer.Reset();

            //swap the buffers and cleanup afterwards
            Sce.PlayStation.HighLevel.GameEngine2D.Director.Instance.GL.Context.SwapBuffers();
            Sce.PlayStation.HighLevel.GameEngine2D.Director.Instance.PostSwap();
        }