views:

232

answers:

1

So, here's what I'm trying to do:

I'm making a game for practice using the GameStateManagement example from creators.xna.com.

The whole of the system is too much to explain here, so experience with the sample is kind of necessary.

The gist of it is that there are multiple game screens that overlay one another. One contains a board, overlayed above it is a few card images. The end goal is to be able to drag-and-drop the card image onto the table (or click it, the method isn't really the problem).

The actual question, then, is how can I pass data from one screen (the overlayed cards) to the other (the table).

I considered that it might be possible to create an event that gets fired when I drag-and-drop a card or click it or what have you, and then register an event handler on the other screen to handle it.

I, however, have pretty much no experience with custom events in C#. I'm not sure if all fired events go into a big "event pool" somewhere and handlers can pick them up regardless of where they are or how that works. I ask because the table screen and the overlayed screen are separate classes that both deal with drawing and updating, not with sending information around to one another.

Hopefully this is enough information to outline the problem decently. Any tips/advice are welcomed.

Thanks!

+2  A: 

After some more experimenting, it looks like events are the way to go.

Without knowing the details of how events work, it seems that a fired event can be picked up from just about anywhere, so long as you register to receive it.

So, the solution to my problem was to create an "OnDrag" event in my "Hand Screen." Then to register to handle this event in the "Table Screen."

This resource helped me get going with the basic custom event handling: Writing C# Custom Events

Anthony Compton