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.