Hi William-

Would the following scenario work for your use case?...

1.  When damage occurs, throw an object representing it into a collection.
2.  Have a single timer that repeatedly fires a "cleanUp:" method, every five 
seconds or so.
3.  In cleanUp:, go through the collection and remove a visual representation 
and take the object out of the collection if the visual representation is out 
of sight.  Do nothing and leave it in the collection if in sight.

It seems to me that this would (mostly) feel the same to the user as your 
scenario... damage would disappear if it was out of sight and older than 5 
seconds.  There would be a possibility of something not getting cleaned up if 
the user repeatedly brought the damage back into the field of vision and it 
never managed to be out of vision when the timer fired.

For a closer approximation, I might add a counter to the object stored in the 
collection, start it with a value of 5, and decrement it every time the object 
was out of sight.  When it reached zero, I'd remove it from the collection.  
The single master timer could fire every second in this scenario.

Food for thought - good luck!

John

On Jul 1, 2014, at 12:21 PM, William Squires <wsqui...@satx.rr.com> wrote:

>  What would be the best way to make an NSTimer that could pause/un-pause its 
> timing? Subclassing? Containment? Just roll my own with 
> performWithSelector:afterDelay:? That is, if I (my code) creates a (smart) 
> NSTimer with a duration of 5 seconds, then three seconds later I need to 
> pause the timer, the timer should un-pause with 2 seconds left on it, not 
> revert back to a duration of 5 seconds.
> 
> Use-case:
>  I have a (fictitious) FPS game in which the players or bots can "damage" the 
> scenery by leaving blast marks. A timer should remove these "decorations" 
> after a given delay, but I want the timers to pause if any players/bots are 
> within line-of-sight of the decorations. The timer should then un-pause once 
> all the players and bots are out of line-of-sight (self-repairing nanotech 
> scenery, anyone?)
>  With a normal timer, you'd have to [<timer> invalidate], and/or re-create a 
> new NSTimer instance, which would reset the time.
>  Another good use is a "smartly" timed weapon/power-up spawn point. If the 
> player (or a bot) is too close, the timer will pause, preventing the spawning 
> of the weapons/power-ups, but as soon as no players or bots are close by, the 
> timer will resume, and a new weapon or power-up will spawn there. This would 
> discourage "camping" around known spawn points! :)
> 
> Or has this "wheel" already been invented?
> 
> 
> _______________________________________________
> 
> Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)
> 
> Please do not post admin requests or moderator comments to the list.
> Contact the moderators at cocoa-dev-admins(at)lists.apple.com
> 
> Help/Unsubscribe/Update your Subscription:
> https://lists.apple.com/mailman/options/cocoa-dev/john%40positivespinmedia.com
> 
> This email sent to j...@positivespinmedia.com


_______________________________________________

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com

Help/Unsubscribe/Update your Subscription:
https://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to arch...@mail-archive.com

Reply via email to