Welcome, Guest. Please login or register. Did you miss your activation email?

Author Topic: Trying to Figure out how to show a new Window  (Read 2598 times)

0 Members and 1 Guest are viewing this topic.

Geoffry_the_Deprogrammer

  • Newbie
  • *
  • Posts: 14
    • View Profile
    • Email
Trying to Figure out how to show a new Window
« on: November 02, 2014, 11:04:13 pm »
I am using SFML in C# and am having difficulties figuring out how to Display a second window in my program, there are no errors obvious with the code, as it runs fine, however it does not display the second window when commanded... I have no idea why, and I cant see any obvious issues having tried replicating the code for the first window...

If anyone has any idea what I might be doing wrong, or can tell me what I should try doing that would be much appreciated...  :)
« Last Edit: November 03, 2014, 09:51:47 am by Geoffry_the_Deprogrammer »

Nexus

  • SFML Team
  • Hero Member
  • *****
  • Posts: 6286
  • Thor Developer
    • View Profile
    • Bromeon
Re: Trying to Figure out how to show a new Window
« Reply #1 on: November 02, 2014, 11:18:30 pm »
Please read this thread and edit your question accordingly. Use code tags and keep the code minimal. To display a window, you don't need loads of classes, methods and properties :)
Zloxx II: action platformer
Thor Library: particle systems, animations, dot products, ...
SFML Game Development:

Geoffry_the_Deprogrammer

  • Newbie
  • *
  • Posts: 14
    • View Profile
    • Email
Re: Trying to Figure out how to show a new Window
« Reply #2 on: November 03, 2014, 09:53:52 am »
yeah, sorry, Im no good at communication with Humans, nonetheless I have attempted to make the question more simple, though I think ive just made it worse...

eXpl0it3r

  • SFML Team
  • Hero Member
  • *****
  • Posts: 10846
    • View Profile
    • development blog
    • Email
Re: Trying to Figure out how to show a new Window
« Reply #3 on: November 03, 2014, 10:35:43 am »
Well now there's simply no code, so we've no idea what you do are what you don't do.
Provide a minimal but complete example and make sure to use the code tag.
Official FAQ: https://www.sfml-dev.org/faq.php
Official Discord Server: https://discord.gg/nr4X7Fh
——————————————————————
Dev Blog: https://duerrenberger.dev/blog/

Geoffry_the_Deprogrammer

  • Newbie
  • *
  • Posts: 14
    • View Profile
    • Email
Re: Trying to Figure out how to show a new Window
« Reply #4 on: November 03, 2014, 10:58:36 am »
does this help at all...?

public static class Program
    {
        private static bool isFullScreen = false;
        public static VideoMode screenRes = new VideoMode(400, 300);

        private static Game game;
        public static Game Game
        {
            get { return game; }
        }

        private static Encryption encryption;
        public static Encryption Encryption
        {
            get { return encryption; }
        }

        private static RenderWindow window;
        public static RenderWindow Window
        {
            get { return window; }
            set { window = value; }
        }

        private static RenderWindow windowencryipt;
        public static RenderWindow WindowEncyript
        {
            get { return windowencryipt; }
            set { windowencryipt = value; }
        }


        private static DateTime previousTick;
        public static DateTime PreviousTick
        {
            get { return previousTick; }
        }

        private static TimeSpan tickLength;
        /// Length of time between each update call
        /// </summary>
        public static TimeSpan TickLength
        {
            get { return tickLength; }
        }

        private static int fps;
        public static int FPS
        {
            get { return fps; }
        }

        private static float delta;

        static void Main(string[] args)
        {

            //Window = new RenderWindow(VideoMode.DesktopMode, "0", Styles.Fullscreen);
            game = new Game();
            encryption = new Encryption();
            if (isFullScreen)
            {
                screenRes = VideoMode.DesktopMode;
                window = new RenderWindow(screenRes, "0", Styles.Fullscreen);
                windowencryipt = new RenderWindow(screenRes, "0", Styles.Fullscreen);
            }
            else
                window = new RenderWindow(screenRes, "0", Styles.Default);
            windowencryipt = new RenderWindow(screenRes, "0", Styles.Default);

            WindowEncyript.Closed += new EventHandler(Exit);
            WindowEncyript.SetVerticalSyncEnabled(true);
            Window.Closed += new EventHandler(Exit);
            Window.SetVerticalSyncEnabled(true);

            SetFPS(60);
            Assets.Initialize();
            Game.Initialize();
            Encryption.Initialize();

            while (Window.IsOpen())
            {
                if (PreviousTick.Add(TickLength) <= DateTime.Now)
                {
                    Update();
                    Draw();
                }
            }

            while (WindowEncyript.IsOpen())
            {
                if (PreviousTick.Add(TickLength) <= DateTime.Now)
                {
                    Update();
                    Draw();
                }
            }
        }

        private static void Draw()
        {
            Window.Clear(Color.White);
            Game.Draw(Window, delta);
            Window.Display();

            WindowEncyript.Clear(Color.White);
            Encryption.Draw(WindowEncyript, delta);
            WindowEncyript.Display();

            //if (Game.Test == true)
            //{
            //    WindowEncyript.Display();
            //    //Window.Close();
            //}
            //Window.Display();
        }

        private static void Update()
        {
            // Launch all events
            Window.DispatchEvents();
            WindowEncyript.DispatchEvents();
            //Calculate delta time
            delta = (float)DateTime.Now.Subtract(previousTick).TotalSeconds;

            Game.Update(window, delta);
            Encryption.Update(windowencryipt, delta);

            previousTick = DateTime.Now;

            if (Keyboard.IsKeyPressed(Keyboard.Key.Escape))
                window.Close();
            windowencryipt.Close();
        }

        public static void Exit(object obj, EventArgs args)
        {
            Window.Close();
            WindowEncyript.Close();
        }

eXpl0it3r

  • SFML Team
  • Hero Member
  • *****
  • Posts: 10846
    • View Profile
    • development blog
    • Email
AW: Trying to Figure out how to show a new Window
« Reply #5 on: November 03, 2014, 11:16:16 am »
It's not minimal, lots of stuff we don't care about, given the problem...
I hope you realize that you can't have two fullscreen windows...

A minimal example would be: Entry point, Create two windows, optionally process events.
Official FAQ: https://www.sfml-dev.org/faq.php
Official Discord Server: https://discord.gg/nr4X7Fh
——————————————————————
Dev Blog: https://duerrenberger.dev/blog/

Geoffry_the_Deprogrammer

  • Newbie
  • *
  • Posts: 14
    • View Profile
    • Email
Re: Trying to Figure out how to show a new Window
« Reply #6 on: November 03, 2014, 11:18:42 am »
yeah, i realise that, I were just Trying to replicate my earlier code for the first window, and yeah, sorry its not minimal, but im really not sure where i should be looking as I have no idea what im doing wrong...

eXpl0it3r

  • SFML Team
  • Hero Member
  • *****
  • Posts: 10846
    • View Profile
    • development blog
    • Email
AW: Trying to Figure out how to show a new Window
« Reply #7 on: November 03, 2014, 11:20:00 am »
If you don't understand your own code, there isn't much we can do...
Official FAQ: https://www.sfml-dev.org/faq.php
Official Discord Server: https://discord.gg/nr4X7Fh
——————————————————————
Dev Blog: https://duerrenberger.dev/blog/

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32504
    • View Profile
    • SFML's website
    • Email
Re: Trying to Figure out how to show a new Window
« Reply #8 on: November 03, 2014, 12:18:21 pm »
Quote
sorry its not minimal, but im really not sure where i should be looking as I have no idea what im doing wrong...
Remove all the code that don't make the problem disappear. Keep only what's needed to reproduce it.
Laurent Gomila - SFML developer

Ztormi

  • Jr. Member
  • **
  • Posts: 71
  • Web developer by day. Game developer by night.
    • View Profile
Re: Trying to Figure out how to show a new Window
« Reply #9 on: November 03, 2014, 12:22:25 pm »
does this help at all...?

snip...


Few things I noticed.

You are missing brackets from else clause:

             if (isFullScreen)
            {
                screenRes = VideoMode.DesktopMode;
                window = new RenderWindow(screenRes, "0", Styles.Fullscreen);
                windowencryipt = new RenderWindow(screenRes, "0", Styles.Fullscreen);
            }
            else
                window = new RenderWindow(screenRes, "0", Styles.Default);
                windowencryipt = new RenderWindow(screenRes, "0", Styles.Default);
           
Second while loop is never happening unless you close the first window, if you are going to render both of them you should do something like:
           
            while (Window.IsOpen() && WindowEncyript.IsOpen())
            {
                if (PreviousTick.Add(TickLength) <= DateTime.Now)
               {
                    Update();
                    Draw();
                }
             }
           
You are missing brackets in Update method so the second window always gets closed:

           
            if (Keyboard.IsKeyPressed(Keyboard.Key.Escape))
                window.Close();
                windowencryipt.Close();

Also not sure if you are aware of this but instead of writing
       
        private static Encryption encryption;
        public static Encryption Encryption
        {
            get { return encryption; }
        }

        private static RenderWindow window;
        public static RenderWindow Window
        {
            get { return window; }
            set { window = value; }
        }
You can just use
 
        public static Encryption Encryption {get; private set; }
        public static RenderWindow Window {get; set;}

Geoffry_the_Deprogrammer

  • Newbie
  • *
  • Posts: 14
    • View Profile
    • Email
Re: Trying to Figure out how to show a new Window
« Reply #10 on: November 04, 2014, 10:03:14 pm »
thanks, yeah, it was just the missing bracket... I should probably be more observant of my own code... Thanks for the help...  :)