Every time update events happen I want to callback a static class function. Any ideas on how to do this. ofAddListener seems to want to take a pointer to an object. But I dont have one? I tried passing NULL as the pointer but it did not work.
right now i’m creating a new class just for update listening. Them making an instance from that class, which is a static class member. Anyone know a better way?
openFrameworks doesn’t provide directly a way of making a static function or a non member function a listener but you can use Poco syntax (the library in which OF events are based):
ofEvents().update += Poco::priorityDelegate(&updateFunction,OF_EVENT_ORDER_APP);
where updateFunction, is a static or c function with signature:
void updateFunction(ofEventArgs & args)
Thanks Arturo!
does using -= remove listeners? How do I remove listeners?
yeah, just use the same syntax with -=
I have a problem when I do something like
ofEvents().update += Poco::priorityDelegate(&updateFunction,OF_EVENT_ORDER_APP);
ofEvents().update += Poco::priorityDelegate(&updateFunction,OF_EVENT_ORDER_APP);
It seems to be adding the listener twice? Is there any way check whether the function has been added already?
no but you can just remove it before adding it, remove will just do nothing if it wasn’t added before
cool trick thanks!