I have a class "KeyEvent"; one of which:
public delegate void eventmethod(object[] args);
And the method passed to the object in the constructor is stored in this element:
private eventmethod em;
Constructor:
public KeyEvent(eventmethod D) { em = D; } public KeyEvent(eventmethod D, object[] args) : this(D) { this.args = args; } public KeyEvent(Keys[] keys, eventmethod D, object[] args) : this(keys, D) { this.args = args; }
Then the eventmethod is called using the public ThrowEvent method:
public void ThrowEvent() { if (!repeat && thrown) return; em.DynamicInvoke(args); this.thrown = true; }
As far as I can see, this compiles fine. But when I try to instantiate this class (KeyEvent), I am doing something wrong. This is what I have so far:
object[] args = {new Vector2(0.0f, -200.0f)}; Keys[] keys = { Keys.W }; KeyEvent KeyEvent_W = new KeyEvent(keys, new KeyEvent.eventmethod(GameBase.ChangeSquareSpeed), args);
GameBase.ChangeSquareSpeed ββis not doing anything at the moment, but it looks like this:
static public void ChangeSquareSpeed(Vector2 squarespeed) { }
In any case, the error string is:
KeyEvent KeyEvent_W = new KeyEvent(keys, new KeyEvent.eventmethod(GameBase.ChangeSquareSpeed), args);
The error that the compiler gives is:
error CS0123: overload for 'ChangeSquareSpeed' does not match delegate 'BLBGameBase.KeyEvent.eventmethod'
My question is: does this mean that I have to change ChangeSquareSpeed ββto not accept any parameters (in this case, what is the best way to do this?), Or am I doing something syntactically wrong?
Thanks in advance.