First post so hi! (please correct me if I use some term wrong)
I’ve got a class Screen in which I create an instance of another class named Player (let’s call this instance Player). Now, in Screen I have a method called ResetHUD which I would like to call from Player.
How would I do that? The only code inside ResetHUD is 1 line which sets a variable to another variable. As far as I know I can use EventHandler (but since ResetHUD doesn’t need any arguments I’m thinking that I’m using that wrong) or delegates (which I have no idea how to use).
Help is appreciated!
It sounds like you have a containment relationship… the Screen object contains one (or more?) Player objects.
When Screen creates Player, it can set a property on Player indicating the parent (creating) Screen object.
You can also use events (events by the way can have parameters, or not, depending on what you need).
This is my favorite tutorial on events and delegates in C#. Starts simple and builds on each step.
http://www.akadia.com/services/dotnet_delegates_and_events.html