http://www.dreaminco...das-and-events/
In the class Main, how can I get the Mouse_LeftClick event method to access other methods/properties of the main class?
I'm guessing it's the protected virtual void.
MyDelegates events = new MyDelegates();
class Main
{
public Game1()
{
//...
events.Mouse_LeftClick += new EventHandler<EventArgs>(Mouse_LeftClick);
}
public static void Mouse_LeftClick(object sender, EventArgs e)
{
//event
}
public void Update()
{
MouseState mouseState = Mouse.GetState();
events.LeftClick(mouseState);
}
}
class MyDelegates
{
#region LeftClick
public event EventHandler<EventArgs> Mouse_LeftClick;
public void LeftClick(MouseState mouseState)
{
if (mouseState.LeftButton == ButtonState.Pressed)
this.OnMouse_LeftClick(EventArgs.Empty);
}
protected virtual void OnMouse_LeftClick(EventArgs e)
{
EventHandler<EventArgs> tempHandler = this.Mouse_LeftClick;
if (tempHandler != null)
tempHandler(this, EventArgs.Empty);
}
}

New Topic/Question
Reply




MultiQuote





|