From what I understand, if you have an event dispatched, it sends to all listeners (not just the class you assigned to). So am I correct in that if we want to only have the function respond to ‘it’s’ event (not all events) we can check who the sender is and see if it matches the one in the class (if there’s multiple classes)? I’m trying to figure out how to make an event only respond to it’s own dispatch, not all of them.
For example, if there’s a timer event in class “Ball” and each ball needs it’s own independent timer complete event (not the same event), how do we check for which timer dispatched the event if the event is dispatched to all Ball instances?
How can we get the sender in the event function or is there a different/better way to have a class respond to it’s own event (not all events of its type)?
and i have this error “No matching function for call to ‘ofAddListener’”. Do you know why?
Maybe i don’t understand completely difference from two different way to use ofAddListener and how many parameters i have to pass. :-\
//--------------------------------------------------------------
void EventClass::notifyEvent()
{
int i = 1; // dummy int, because ofNotifyEvent(...) needs an argument
ofNotifyEvent(myEvent, i, this);
}
//--------------------------------------------------------------
ListenerClass::ListenerClass()
{
eventClass = new EventClass();
// ERROR: "No matching function for call to 'ofAddListener'
ofAddListener(eventClass->myEvent, this, &ListenerClass::eventCallback);
}
//--------------------------------------------------------------
void ListenerClass::eventCallback(void* _sender, int& _i)
{
// do whatever...
}