PROBLEM FIXED. IGNORE THIS!!!!So I'm currently working on a menu system. A problem I'm running into is event handling when trying to hover over/click buttons I placed on the screen.
The menu system is based on "Scenes" which are like pages. The scenes contain the information to create and draw buttons as well as draw anything else I want to display.
Each scene has "register_mouseclick" and "register_mousemove" override methods. They look like this:
public override void register_mouseclick( object sender, MouseButtonEventArgs e )
{
RenderWindow window = (RenderWindow)sender;
if( e.Button.GetHashCode() == 0 )
{
foreach( Button btn in buttons )
{
btn.check_mouse_click();
}
}
}
public override void register_mousemove( object sender, MouseMoveEventArgs e )
{
foreach( Button btn in buttons )
{
btn.check_hover_state( e );
}
}
And I register these events through the SceneHandler:
public void register_events
( ref RenderWindow window
) { foreach( Scene s
in scenes
) { if( s
.id == current_scene
) { window
.MouseButtonPressed += new EventHandler
<MouseButtonEventArgs
>(s
.register_mouseclick); window
.MouseMoved += new EventHandler
<MouseMoveEventArgs
>(s
.register_mousemove); } } } Now the problem I'm running into is when I switch scenes; the events are not registered. They're registered on the default scene but once I change to a different scene the events are no longer registered.
I'm calling the register_events function like so:
public void init
(){ // ... SceneHandler SceneManager
= new SceneHandler
(); SceneManager
.register_events( ref window
); // ... while( window
.IsOpen() ) { window
.DispatchEvents(); window
.Clear(); SceneManager
.draw_scene( ref window
); window
.Display(); }} Now if I were to put the register_events function into the while "window is open" loop it works BUT the game will obviously lag.
How could I solve this problem?