Gamua / Sparrow-Framework

The Open Source Game Engine for iOS
http://www.sparrow-framework.org
Other
294 stars 83 forks source link

copy-paste error? #29

Open sunnyawake opened 10 years ago

sunnyawake commented 10 years ago

in SPDisplayObject.removeEventListenerForType:

if ([eventType isEqualToString:SPEventTypeEnterFrame] &&
   ![self hasEventListenerForType:SPEventTypeEnterFrame])
PrimaryFeather commented 10 years ago

What exactly is the problem? I still can't spot it g.

What this code does is executing the if-clause only the first time you're adding an enter-frame listener. That's for an optimization: a list of objects that the "enterFrame" event is sent to (instead of having to iterate over the complete display tree).

sunnyawake commented 10 years ago

it's in the removeEventListener() method, but has a "!" ?

PrimaryFeather commented 10 years ago

Yeah, but that's fine! Note that in the line above that one, "super removeEventListeners..." is called. So the listener was already removed. The "if" now checks if there is another enter frame listener remaining; if not, that object can be removed from the list.

See what I mean?