当前位置: 首页>>代码示例>>C#>>正文


C# RenderWindow.DispatchEvents方法代码示例

本文整理汇总了C#中SFML.Graphics.RenderWindow.DispatchEvents方法的典型用法代码示例。如果您正苦于以下问题:C# RenderWindow.DispatchEvents方法的具体用法?C# RenderWindow.DispatchEvents怎么用?C# RenderWindow.DispatchEvents使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在SFML.Graphics.RenderWindow的用法示例。


在下文中一共展示了RenderWindow.DispatchEvents方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: Run

        public void Run()
        {
            window = new RenderWindow(new VideoMode(800, 480), "sfml-ui Examples", Styles.Default);
            window.Closed += window_OnCloseRequest;
            window.Resized += window_Resized;

            uimanager = new UISceneManager();
            uimanager.Init(window);

            scene1 = new Scene(ScrollInputs.None);
            scene1.Size = new Vector2f(window.Size.X, window.Size.Y);
            scene1.AddComponent(new TextControl(new Font("font.ttf"), 50) { Size = new Vector2f(800, 100), Color = Color.White, Text = "Hello World", TextAlignment = Alignment.MiddleCenter, Anchor = AnchorPoints.Left | AnchorPoints.Right | AnchorPoints.Top, BackgroundColor = Colors.SteelBlue });
            scene1.AddComponent(new TextControl(new Font("font.ttf"), 16) { Size = new Vector2f(600, 100), Position = new Vector2f(100, 150), Color = Color.Black, Text = "This is an example of sfml-ui, an ui library for SFML.Net", TextAlignment = Alignment.MiddleCenter, Anchor = AnchorPoints.Left | AnchorPoints.Right | AnchorPoints.Top });
            scene1.AddComponent(new PictureControl("example-100.png") { Size = new Vector2f(100, 100), Position = new Vector2f(0, 0), Anchor = AnchorPoints.Left | AnchorPoints.Top });
            scene1.AddComponent(new ButtonControl(new Font("font.ttf"), 16, "button.png", "button_hover.png", "button_pressed.png") { Size = new Vector2f(150, 49), Position = new Vector2f(50, 250), Anchor = AnchorPoints.Left | AnchorPoints.Top, Text = "Press Me :)" });

            uimanager.CurrentScene = scene1;

            while (window.IsOpen())
            {
                window.DispatchEvents();
                window.Clear(Colors.WhiteSmoke);

                uimanager.Render(window);

                window.Display();
            }
        }
开发者ID:Scellow,项目名称:sfml-ui,代码行数:28,代码来源:Example.cs

示例2: Main

        static void Main(string[] args)
        {
            RenderWindow window = new RenderWindow(new VideoMode(800, 600), "Test01");
            window.Closed += (object sender, EventArgs e) => { (sender as Window).Close(); };

            Font font = new Font("SnowflakeLetters.ttf");
            Text text = new Text("BALD IST WEIHNACHTEN!", font);
            Color col1 = new Color(123, 12, 12);
            text.Position = new Vector2f(200, 200);
            CircleShape shape = new CircleShape(20, 8);
            shape.FillColor = Color.White;
            shape.Position = new Vector2f(50, 50);
            float a, c;
            a = c = 50f;

            while (window.IsOpen())
            {
                window.Clear(col1);
                window.Draw(text);
                if (Keyboard.IsKeyPressed(Keyboard.Key.Left) && a > 0)
                    a -= 0.1f;
                if (Keyboard.IsKeyPressed(Keyboard.Key.Right) && a < window.Size.X - shape.Radius * 2)
                    a += 0.1f;
                if (Keyboard.IsKeyPressed(Keyboard.Key.Down) && c < window.Size.Y - shape.Radius * 2)
                    c += 0.1f;
                if (Keyboard.IsKeyPressed(Keyboard.Key.Up) && c >  0)
                    c -= 0.1f;
                window.Draw(shape);
                shape.Position = new Vector2f(a, c);

                window.Display();
                window.DispatchEvents();
            }
        }
开发者ID:HanHangit,项目名称:Visual-Test,代码行数:34,代码来源:Program.cs

示例3: Main

        static void Main(string[] args)
        {
            // initialize window and view
            win = new RenderWindow(new VideoMode(1000, 700), "Hadoken!!!");
            view = new View();
            resetView();
            gui = new GUI(win, view);

            // exit Program, when window is being closed
            //win.Closed += new EventHandler(closeWindow);
            win.Closed += (sender, e) => { (sender as Window).Close(); };

            // initialize GameState
            handleNewGameState();

            // initialize GameTime
            GameTime gameTime = new GameTime();
            gameTime.Start();

            // debug Text
            Text debugText = new Text("debug Text", new Font("Fonts/calibri.ttf"));

            while (running && win.IsOpen())
            {
                KeyboardInputManager.update();

                currentGameState = state.update();

                // gather draw-stuff
                win.Clear(new Color(100, 149, 237));    //cornflowerblue ftw!!! 1337
                state.draw(win, view);
                state.drawGUI(gui);

                // first the state must be drawn, before I can change the currentState
                if (currentGameState != prevGameState)
                {
                    handleNewGameState();
                }

                // do the actual drawing
                win.SetView(view);
                win.Display();

                // check for window-events. e.g. window closed        
                win.DispatchEvents();

                // update GameTime
                gameTime.Update();
                float deltaTime = (float)gameTime.EllapsedTime.TotalSeconds;

                // idleLoop for fixed FrameRate
                float deltaPlusIdleTime = deltaTime;
                while (deltaPlusIdleTime < (1F / fixedFps))
                {
                    gameTime.Update();
                    deltaPlusIdleTime += (float)gameTime.EllapsedTime.TotalSeconds;
                }
                Console.WriteLine("real fps: " + (int)(1F / deltaPlusIdleTime) + ", theo fps: " + (int)(1F / deltaTime));
            }
        }
开发者ID:Greaka,项目名称:RuneShift,代码行数:60,代码来源:Program.cs

示例4: Game

        public Game()
        {
            Settings settings = Settings.Load("settings.txt");

            renderWindow = new RenderWindow(new VideoMode(settings.Width, settings.Height), "Nations", Styles.Close);
            renderWindow.Closed += closed;

            currentState = new TestState(this);

            // Loop
            time = new Stopwatch();
            running = true;
            updateRate = 1.0 / 60.0;

            time.Start();
            double previous = time.Elapsed.TotalSeconds;
            double lag = 0;

            while (running)
            {
                double current = time.Elapsed.TotalSeconds;
                double elapsed = current - previous;
                previous = current;
                lag += elapsed;

                while (lag >= updateRate)
                {
                    renderWindow.DispatchEvents();
                    currentState.Update();
                    lag -= updateRate;
                }

                currentState.Render();
            }
        }
开发者ID:toaster468,项目名称:Nations,代码行数:35,代码来源:Game.cs

示例5: Main

        public static void Main(string[] args)
        {
            var win = new RenderWindow(new VideoMode(800, 600), "Some Crappy Zombie Thing");
            win.Closed += (sender, e) => win.Close ();
            var curtime = DateTime.Now;
            double dt = 0;
            double frametime;
            win.SetVisible (true);
            EntityManager.Add (new RectangleTestEntity(true));
            EntityManager.Add (new DebugInfo());
            EntityManager.Add (new TileEntity("data/graphics/test_tileset.xml", 0, 1));
            EntityManager.Add (new TileEntity("data/graphics/test_tileset.xml", "45down", new Vector2f(35, 40), 1));
            Entity ent = new Entity();
            ent.OnDraw += (sender, e) => e.Surface.Draw (new Text("Loooooonnnnggg Teeeexxxttt") {Position = new Vector2f(700, 500)});
            EntityManager.Add (ent);
            EntityManager.InitializeWindow (win);

            while(win.IsOpen ())
            {
                win.DispatchEvents();
                EntityManager.Draw (win);
                win.Display ();
                frametime = (DateTime.Now-curtime).TotalMilliseconds;
                dt += frametime;
                while (dt >= EntityManager.TimeStep)
                {
                    //Console.WriteLine (dt.ToString ());
                    EntityManager.Update (dt, frametime);
                    dt -= EntityManager.TimeStep;
                }
                curtime = DateTime.Now;
            }
        }
开发者ID:Phyxius,项目名称:SomeZombieGame,代码行数:33,代码来源:Main.cs

示例6: Main

        private static void Main(string[] args)
        {
            var contextSettings = new ContextSettings {
                DepthBits = 32
            };
            var window = new RenderWindow(new VideoMode(640, 480), "JukeSaver spike: SFML Basic", Styles.Default, contextSettings);
            window.SetActive();

            window.Closed += OnClosed;
            window.KeyPressed += OnKeyPressed;

            int r = 0, g = 0, b = 0;
            var shape = new CircleShape() {
                Position = new Vector2f(320, 240),
            };

            while (window.IsOpen()) {
                window.DispatchEvents();
                window.Clear(new Color((byte)r, (byte)g, (byte)b));

                shape.Radius = (float)(80.0 + GetPulse() * 40.0);
                shape.Origin = new Vector2f(shape.Radius * 0.5f, shape.Radius * 0.5f);
                shape.Position = new Vector2f(320 - shape.Radius * 0.5f, 240 - shape.Radius * 0.5f);

                shape.FillColor = new Color(50, (byte)(160 + 80 * GetPulse()), (byte)(40 - (40 * GetPulse())));

                window.Draw(shape);
                window.Display();
            }
        }
开发者ID:nathanchere,项目名称:Spikes_JukeSaver,代码行数:30,代码来源:Program.cs

示例7: Main

        // EINBINDEN VON SFML.NET
        //  - Projektmappen-Explorer öffnen
        //  - Rechtklick -> Verweis hinzufügen
        //  - In der Linkenspalte "Durchsuchen"
        //  - Ganz unten erneut auf "Durchsuchen"
        //  - SFML.NET Ordner öffnen -> Libs
        //  - Alle Auswählen und hinzufügen
        //  - Schauen ob alle markiert sind und OK
        //
        //  - Rechtsklick -> Hinzufügen -> Vorhandenes Element
        //  - SFML.NET Ordner öffnen -> extlibs
        //  - ggf. "Alle Dateitypen (.*)" auswählen
        //  - Alle Auswählen und hinzufügen
        //  - Im Projektmappen-Explorer die 5 .dll auswählen
        //  - Rechtsklick -> Eigenschaften
        //  - Ins Ausgabeverzeichniskopieren -> "Immer kopieren" oder "Kopieren wenn neuer"
        // KONSOLE AUSSCHALTEN
        //  - Projektmappen-Explorer öffnen
        //  - Rechtsklick auf das Projekt (Intro2D-02-Beispiel) -> Eigenschaften
        //  - In den Reiter "Anwendung" (automatisch offen) wechseln
        //  - Ausgabetyp -> "Windows-Anwendung"
        // WICHTIG !!!!!!
        //  - WENN IHR DIESES PROJEKT WEITERVERWENDEN WOLLT, MÜSST IHR DIE VERWEISE (erster Teil) NEU HINZUFÜGEN
        // Wird für Programm ablauf benötigt
        static void Main()
        {
            //initialisiert ein RenderWindow
            RenderWindow win = new RenderWindow(new VideoMode(800, 600), "Test Window");

            //fügt die Close Methode dem Closed Event von dem RenderWindow hinzu
            win.Closed += Close;
            //fancy alternativen:
            //win.Closed += (sender, e) => { ((RenderWindow)sender).Close(); };
            //win.Closed += delegate { win.Close(); };

            //solange das Window offen ist
            while (win.IsOpen())
            //in SFML2.2 while(win.IsOpen)
            {
                //hellblau oder so
                win.Clear(new Color(40, 150, 200));

                //trigger alle events
                win.DispatchEvents();

                //zeige alles gezeichnete an
                win.Display();
            }
        }
开发者ID:endert,项目名称:Intro2D,代码行数:49,代码来源:Program.cs

示例8: Main

        public static void Main(string[] args)
        {
            window = new RenderWindow(new VideoMode(800, 600), "SFML window");
            window.SetVisible(true);
            window.SetVerticalSyncEnabled(true);
            window.Closed += OnClosed;
            window.MouseMoved += OnMouse;
            window.MouseLeft += Window_MouseLeft;
            window.Resized += Window_Resized;

            List<Button> buttons = new List<Button>();

            for (int i = 0; i < 10; i++)
            {
                buttons.Add(new Button(new Vector2f(i*200, 100), new Vector2f(75, 20)));
            }

            while (window.IsOpen)
            {
                window.DispatchEvents();
                window.Clear(new Color(50, 50, 50));
                GUIManager.GuiManager.Update(Mouse.GetPosition(window).X, Mouse.GetPosition(window).Y);
                foreach (var item in buttons)
                {
                    window.Draw(item);
                }
                window.Display();
            }
        }
开发者ID:FelixKimmerle,项目名称:SFMLGui,代码行数:29,代码来源:Program.cs

示例9: Main

        static void Main(string[] args)
        {
            Files.log("Game started.");

            Console.Title = "Asialaide";

            new Character("Player", 1, 200, 300);

            Drawing.initialise();
            window = Drawing.window; // A local reference.

            // Create events.
            window.Closed += new EventHandler(Program.OnClose);
            window.KeyPressed += new EventHandler<KeyEventArgs>(Input.OnKeyPressed);

            // Load files.
            Files.load("data\\graphics\\crf_char.png");

            // The game loop.
            while (window.IsOpen())
            {
                // Process events.
                window.DispatchEvents();

                // Draw everything.
                Drawing.drawWindow();
            }
        }
开发者ID:vladivanovic,项目名称:wakarimasen,代码行数:28,代码来源:Program.cs

示例10: Main

        static int Main(string[] args)
        {
            // The Screen or Window
            VideoMode videoMode = new VideoMode(1024, 768);
            RenderWindow window = new RenderWindow(videoMode,
                "Learn SFML");
            window.Closed += new EventHandler(window_Closed);
            window.MouseButtonPressed += new EventHandler<MouseButtonEventArgs>(window_MouseButtonPressed);
            window.MouseMoved += new EventHandler<MouseMoveEventArgs>(window_MouseMoved);
            window.KeyPressed += new EventHandler<KeyEventArgs>(window_KeyPressed);

            Start();

            Console.Out.WriteLine("Engine Started Successfully!");

            while (window.IsOpen()
                && !quit)
            {
                window.DispatchEvents();

                // Draw
                currentScreen.Draw(window);
                window.Display();
            }
            window.Close();

            return 0;
        }
开发者ID:MrPhil,项目名称:LD24,代码行数:28,代码来源:Program.cs

示例11: Main

        static void Main(string[] args)
        {
            game = new Game();
            game.Start();
            StartupForm startup = new StartupForm();
            DialogResult startupResult;
            do
            {
                startupResult = startup.ShowDialog();
                if (startupResult == DialogResult.Abort)
                {
                    Application.Exit();
                    Environment.Exit(1);
                    return;
                }
            }
            while(startupResult == DialogResult.Cancel);

            app = new RenderWindow(new VideoMode(800, 600), "FTLEdit: Ship Editor", Styles.Default);
            app.Closed += new EventHandler(OnClosed);
            app.KeyPressed += new EventHandler<SFML.Window.KeyEventArgs>(OnKeyPressed);

            app.SetFramerateLimit(30);

            while (app.IsOpen())
            {
                app.DispatchEvents();
                app.Clear();
                game.Draw(app);
                game.Update();
                app.Display();
                if(game.cursorMode != CursorMode.PlacedBGCursor)
                    Application.DoEvents();
            }
        }
开发者ID:nyteshade,项目名称:FTLEdit,代码行数:35,代码来源:Program.cs

示例12: Main

        internal static void Main(string[] args)
        {
            shapes = new List<Shape>();

            window = new RenderWindow(new VideoMode(WINDOW_SIZE.X, WINDOW_SIZE.Y), "Physics Playground", Styles.Titlebar | Styles.Close);
            window.SetVerticalSyncEnabled(true);
            window.SetKeyRepeatEnabled(false);
            SetupEvents();

            Time lastTime = clock.ElapsedTime;

            while(window.IsOpen)
            {
                Time now = clock.ElapsedTime;
                Time frame = now - lastTime;
                lastTime = now;
                lag += frame;

                while(lag >= dt)
                {
                    window.DispatchEvents();

                    if(!paused)
                    {
                        Update();
                    }

                    lag -= dt;
                }

                Draw();
            }
        }
开发者ID:dabbertorres,项目名称:PhysicsPlayground,代码行数:33,代码来源:Game.cs

示例13: Main

        public static void Main()
        {
            VideoMode videoMode = VideoMode.DesktopMode;
            videoMode.Width = 800;
            videoMode.Height = 600;
            using (RenderWindow renderWindow = new RenderWindow(videoMode, "SFML Test"))
            {
                renderWindow.SetFramerateLimit(60);

                Game.Window = renderWindow;
                Game.Init();

                renderWindow.Closed += (sender, e) =>
                {
                    renderWindow.Close();
                };

                Stopwatch stopwatch = new Stopwatch();
                stopwatch.Start();
                while (renderWindow.IsOpen)
                {
                    renderWindow.DispatchEvents();

                    float dTime = stopwatch.ElapsedMilliseconds / 1000f;
                    stopwatch.Restart();
                    Game.ElapsedTime += dTime;

                    if (false && Game.Entities.OfType<Enemy>().Count() < 3)
                    {
                        Game.Entities.Add(new Enemy(Game.Player)
                        {
                            Position = Vector2.Random(renderWindow.Size.X, renderWindow.Size.Y)
                        });
                    }

                    if (Keyboard.IsKeyPressed(Keyboard.Key.Escape))
                    {
                        renderWindow.Close();
                    }

                    // Update code goes here
                    foreach (Entity entity in Game.Entities.ToArray())
                    {
                        entity.Update(dTime);
                    }

                    // Rendering code goes here
                    renderWindow.Clear();

                    foreach (Entity entity in Game.Entities.OrderBy(e => e.RenderPriority))
                    {
                        renderWindow.Draw(entity);
                    }
                    renderWindow.Display();
                }
                renderWindow.Close();
            }
        }
开发者ID:Thunder7102,项目名称:RPG,代码行数:58,代码来源:Program.cs

示例14: HandleEvents

        public static void HandleEvents(RenderWindow rw)
        {
            if (!_eventsInitialized)
            {
                InitEvents(rw);
            }

            rw.DispatchEvents();
        }
开发者ID:Tetramputechture,项目名称:Ending_0.1b,代码行数:9,代码来源:InputHandler.cs

示例15: Main

        public static void Main(string[] args)
        {
            Window = new RenderWindow(new VideoMode(640, 480), "", Styles.Close);
            Window.SetFramerateLimit(60);

            Window.Closed += (sender, eventArgs) => Window.Close();

            Window.Resized += (sender, eventArgs) =>
            {
                var view = new View();
                view.Size = new Vector2f(eventArgs.Width, eventArgs.Height);
                view.Center = view.Size / 2;
                Window.SetView(view);
            };

            Machine = new VirtualMachine(512 * 1024);

            var prog = File.ReadAllBytes("bios.bin");
            for (var i = 0; i < prog.Length; i++)
                Machine.Memory[i] = prog[i];

            var kbd = new Devices.Keyboard(0x02, Window);
            Machine.Attach(kbd);

            var display = new Devices.Display(0x06, Machine, Window);
            Machine.Attach(display);

            var hdd = new Devices.HardDrive(0x08, "disk.img");
            Machine.Attach(hdd);

            var running = true;

            var stepThread = new Thread(() =>
            {
                while (running)
                {
                    Machine.Step();
                }
            });

            stepThread.Start();

            while (Window.IsOpen())
            {
                Window.DispatchEvents();

                Window.Clear();
                Window.Draw(display);
                Window.Display();
            }

            running = false;
            stepThread.Join();
            Machine.Dispose();
        }
开发者ID:Rohansi,项目名称:LoonyVM,代码行数:55,代码来源:Program.cs


注:本文中的SFML.Graphics.RenderWindow.DispatchEvents方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。