Reset() public method

Rebuild the view from a rectangle
public Reset ( FloatRect rectangle ) : void
rectangle FloatRect Rectangle defining the position and size of the view
return void
Exemplo n.º 1
0
        static void Main(string[] args)
        {
            Log.GlobalLevel = Log.Level.Debug;

            RenderWindow app = new RenderWindow(new VideoMode(800, 600), "HP!",
                Styles.Default, new ContextSettings(0, 0, 4));
            app.SetFramerateLimit(60);
            app.Closed += delegate { app.Close(); };
            app.SetVisible(true);
            app.SetActive(true);

            L.I("Assuming assets in \"assets\"");
            Assets assets = new Assets("assets");
            LoadAnimations(assets);

            Level level1 = assets.Level("level1.json");
            Game game = new Game(assets, level1);
            var view = new View();

            int lastFrameTime = Environment.TickCount;
            while (app.IsOpen) {
                app.DispatchEvents();

                float aspect = (float)app.Size.X / app.Size.Y;
                float targetWidth = 20, targetHeight = targetWidth / aspect;
                view.Reset(new FloatRect(0, 0, targetWidth, targetHeight));
                app.SetView(view);

                int ticks = Environment.TickCount;
                float delta = (ticks - lastFrameTime) / 1000F;
                lastFrameTime = ticks;

                game.Update(delta);
                game.Render(app);

                app.Display();
            }
        }
Exemplo n.º 2
0
        /// <summary>
        /// When overridden in the derived class, draws the graphics to the control.
        /// </summary>
        /// <param name="currentTime">The current time.</param>
        protected override void HandleDraw(TickCount currentTime)
        {
            base.HandleDraw(currentTime);

            if (DesignMode)
            {
                return;
            }

            if (_drawingManager.RenderWindow == null)
            {
                return;
            }

            if (Grh == null)
            {
                return;
            }

            Grh.Update(currentTime);

            m.Update(currentTime);

            _drawingManager.Update(currentTime);

            var sb = _drawingManager.BeginDrawWorld(_camera);

            if (sb == null)
            {
                return;
            }

            // Change the view
            var oldView = RenderWindow.GetView();

            _drawView.Reset(new FloatRect(Camera.Min.X, Camera.Min.Y, Camera.Size.X, Camera.Size.Y));
            RenderWindow.SetView(_drawView);

            try
            {
                try
                {
                    Grh.Draw(sb, Vector2.Zero, Color.White);
                }
                catch (LoadingFailedException)
                {
                    // A LoadingFailedException is generally fine here since it probably means the graphic file was invalid
                    // or does not exist
                }

                // Draw the walls
                if (Walls != null)
                {
                    foreach (var wall in Walls)
                    {
                        var rect = wall.ToRectangle();
                        RenderRectangle.Draw(sb, rect, _autoWallColor);
                    }
                }

                m.Draw(sb, Camera);
            }
            finally
            {
                _drawingManager.EndDrawWorld();

                // Restore the view
                RenderWindow.SetView(oldView);
            }
        }