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

Show Posts

This section allows you to view all posts made by this member. Note that you can only see posts made in areas you currently have access to.


Messages - aceman1209

Pages: [1]
1
DotNet / Re: Copy events in a new render window
« on: March 15, 2018, 05:26:07 pm »
I was responded to a ru.stackoverflow.com. I think this is a working solution.

Add my own event with Render Window event args.
    public event EventHandler<SizeEventArgs> Resized;
 

Then add a listener for Render Window resized event. I wrote a method for this.

         private void LinkEvents()
        {
            renderWindow.Resized += RenderWindow_Resized;
        }
 

When I recreate window I call LinkEvents() method after window initializing.

Listener method is very simple.
     private void RenderWindow_Resized(object sender, SizeEventArgs e) => Resized?.Invoke(sender, e);
 

When render window event works i call a my event Invoke with arguments. And it works.

2
If i understood what you need.

You initialize a List every 5 seconds again. If you want add new enemies without delete old ones, you need initalize a List one time and use it for all enemies.

    public static List<Sprite> lst_sprt = new List<Sprite>();
    public static List<float> lst_posx = new List<float>();
    public static List<float> lst_posy = new List<float>();
 

and delete initialization in SpawnEnemy()

You got the  NullReferenceException because List<T> variable without initialization is null.

P.S: I think it's better to use classes, but it looks like you have not worked with them yet.

3
DotNet / Re: Copy events in a new render window
« on: March 14, 2018, 09:44:42 pm »
This is my own GameWindow class
namespace Amari.Display
{
    public class GameWindow
    {
        internal RenderWindow renderWindow;

        public Viewport viewport;
        public bool IsFullscreen { get; private set; }

        public event EventHandler<SizeEventArgs> Resized;

        public bool IsOpen
        {
            get
            {
                return renderWindow.IsOpen;
            }
        }

        public GameWindow(bool IsFullScreen)
        {
            renderWindow = new RenderWindow(new VideoMode(800, 600), "", IsFullscreen ? Styles.Fullscreen : Styles.Default);
        }

        public void UpdateVideoMode(VideoMode videoMode, bool IsFullscreen)
        {
            renderWindow = new RenderWindow(videoMode, "", IsFullscreen ? Styles.Fullscreen : Styles.Default);
        }

        public void DispatchEvents() => renderWindow.DispatchEvents();
        public void Display() => renderWindow.Display();
    }
 

When i use UpdateVideoMode, the window is recreated and apply new videomode but all events will be reseted.

I add a simple code in GameWindow class and change constructor

        public GameWindow(bool IsFullScreen)
        {
            renderWindow = new RenderWindow(new VideoMode(800, 600), "", IsFullscreen ? Styles.Fullscreen : Styles.Default);
            renderWindow.Resized += RenderWindow_Resized;
        }

        private void RenderWindow_Resized(object sender, SizeEventArgs e)
        {
            Console.WriteLine($"Window resized");
        }
 

When i resize a window i get a message in console "Window resized"

Okay, its right.

But i add a two new lines in costructor
    renderWindow.Close();
    VideoModeUpdate(new VideoMode(1280, 720), false);
 

For example i set a new videomode in constructor.

Window initialized and works, but event doesnt.

I attach a screenshots.

Why i need to copy events? Because in other classes i use a renderWindow events and i dont want to update them after every window change. For example, my own mouse class part.

         private void GameWindow_MouseButtonPressed(object sender, MouseButtonEventArgs e)
        {
            is_Button_Pressed[(int)e.Button] = true;
            is_Button_Released[(int)e.Button] = false;
        }

        private void GameWindow_MouseButtonReleased(object sender, MouseButtonEventArgs e)
        {
            is_Button_Pressed[(int)e.Button] = false;
            is_Button_Released[(int)e.Button] = true;    
        }
 

If i recreate window i need to update this events, but object already created and in use. I need write a method for events link to a new window. But it's not convenient.

Sorry for my english, i'm not very strong in it.

4
DotNet / Copy events in a new render window
« on: March 14, 2018, 07:19:04 pm »
Hi all. SFML.net does not have a Create () method for window. And to apply the changes it needs to be closed and re-created. But events will be reset if i recreate window.

How can I copy all the events in a new rendering window?

Pages: [1]