/** Initializes a timer with a target, a selector, an interval in seconds, repeat in number of times to repeat, delay in seconds */
		public CCTimerTargetSelector(System.Object t, TICK_IMP selector, float interval=0, uint repeat=CCScheduler.kCCRepeatForever, float delay=0){
			if(CCDebug.COCOS2D_DEBUG>=1)
				NSUtils.Assert (selector != null, "Method not found for selector - does it have the following form? void name(float dt)");
			_target = t;
			_selector = selector;
			setupTimer (interval, repeat, delay);
		}
Пример #2
0
 /** Initializes a timer with a target(owner), interval in seconds, repeat in number of times to repeat, delay in seconds and a block */
 public CCTimerBlock(System.Object owner, float seconds, string key, TICK_IMP block, uint repeat = CCScheduler.kCCRepeatForever, float delay = 0)
 {
     _block  = block;
     _key    = key;
     _target = owner;
     setupTimer(seconds, repeat, delay);
 }
Пример #3
0
        /**
         * repeat will execute the action repeat + 1 times, for a continues action use kCCRepeatForever
         * delay is the amount of time the action will wait before execution
         */
        public void schedule(TICK_IMP selector, float interval = 0, uint repeat = CCScheduler.kCCRepeatForever, float delay = 0)
        {
            NSUtils.Assert(selector != null, "Argument must be non-nil");
            NSUtils.Assert(FloatUtils.EB(interval, 0), "Arguemnt must be positive");


            _scheduler.schedule(selector, this, interval, repeat, !_isRunning, delay);
        }
Пример #4
0
 /** Initializes a timer with a target, a selector, an interval in seconds, repeat in number of times to repeat, delay in seconds */
 public CCTimerTargetSelector(System.Object t, TICK_IMP selector, float interval = 0, uint repeat = CCScheduler.kCCRepeatForever, float delay = 0)
 {
     if (CCDebug.COCOS2D_DEBUG >= 1)
     {
         NSUtils.Assert(selector != null, "Method not found for selector - does it have the following form? void name(float dt)");
     }
     _target   = t;
     _selector = selector;
     setupTimer(interval, repeat, delay);
 }
Пример #5
0
        public void unschedule(TICK_IMP selector)
        {
            // explicit nil handling
            if (selector == null)
            {
                return;
            }

            _scheduler.unscheduleSelector(selector, this);
        }
Пример #6
0
        /** Unshedules a selector for a given target.
         * If you want to unschedule the "update", use unscheudleUpdateForTarget.
         * @since v0.99.3
         */
        public void unscheduleSelector(TICK_IMP selector, System.Object target)
        {
            if (target == null && selector == null)
            {
                return;
            }

            NSUtils.Assert(target != null, "Target MUST not be nil");
            NSUtils.Assert(selector != null, "Selector MUST not be NULL");

            tHashTimerEntry element = hashForTimers.HASH_FIND_INT(target.GetHashCode());

            if (element != null)
            {
                int timersCount = element.timers.Count;
                for (int i = 0; i < timersCount; i++)
                {
                    CCTimer timer = element.timers[i];
                    if (timer is CCTimerTargetSelector && selector == ((CCTimerTargetSelector)timer).selector)
                    {
                        if (timer == element.currentTimer && !element.currentTimerSalvaged)
                        {
                            element.currentTimerSalvaged = true;
                        }
                        element.timers.RemoveAt(i);
                        if (element.timerIndex >= i)
                        {
                            element.timerIndex--;
                        }
                        if (element.timers.Count == 0)
                        {
                            if (currentTarget == element)
                            {
                                currentTargetSalvaged = true;
                            }
                            else
                            {
                                removeHashElement(element);
                            }
                        }
                        return;
                    }
                }
            }

            // Not Found
            //	NSLog(@"CCScheduler#unscheduleSelector:forTarget: selector not found: %@", selString);
        }
Пример #7
0
        /** The scheduled method will be called every 'interval' seconds.
         * If paused is YES, then it won't be called until it is resumed.
         * If 'interval' is 0, it will be called every frame, but if so, it recommended to use 'scheduleUpdateForTarget:' instead.
         * If the selector is already scheduled, then only the interval parameter will be updated without re-scheduling it again.
         * repeat lets the action be repeated repeat + 1 times, use kCCRepeatForever to let the action run continuously
         * delay is the amount of time the action will wait before it'll start
         *
         * @since v0.99.3, repeat and delay added in v1.1
         */
        public void schedule(TICK_IMP selector, System.Object target, float interval, uint repeat, bool paused, float delay = 0)
        {
            NSUtils.Assert(selector != null, "Argument selector must be non-nil");
            NSUtils.Assert(target != null, "Argument target must be non-nil");

            tHashTimerEntry element = hashForTimers.HASH_FIND_INT(target.GetHashCode());

            if (element == null)
            {
                element        = new tHashTimerEntry();
                element.target = target;
                hashForTimers.HASH_ADD_INT(target.GetHashCode(), element);

                // Is this the 1st element ? Then set the pause level to all the selectors of this target
                element.paused = paused;
            }
            else
            {
                NSUtils.Assert(element.paused == paused, "CCScheduler. Trying to schedule a selector with a pause value different than the target");
            }


            if (element.timers == null)
            {
                element.timers = new List <CCTimer> (10);
            }
            else
            {
                var enumerator = element.timers.GetEnumerator();
                while (enumerator.MoveNext())
                {
                    CCTimer timer = enumerator.Current;
                    if (timer is CCTimerTargetSelector && selector == ((CCTimerTargetSelector)timer).selector)
                    {
                        CCDebug.Log("CCScheduler#scheduleSelector. Selector already scheduled. Updating interval from: {0:0.0000} to {1:0.0000}", timer.interval, interval);
                        timer.interval = interval;
                        return;
                    }
                }
            }
            CCTimerTargetSelector timerSelector = new CCTimerTargetSelector(target, selector, interval, repeat, delay);

            element.timers.Add(timerSelector);
        }
Пример #8
0
		/** Unshedules a selector for a given target.
		 If you want to unschedule the "update", use unscheudleUpdateForTarget.
		 @since v0.99.3
		 */
		public void unscheduleSelector(TICK_IMP selector, System.Object target){
			if (target==null && selector == null) {
				return;			
			}
			
			NSUtils.Assert( target != null, "Target MUST not be nil");
			NSUtils.Assert( selector != null, "Selector MUST not be NULL");
			
			tHashTimerEntry element = hashForTimers.HASH_FIND_INT (target.GetHashCode());
			if (element != null) {
				int timersCount = element.timers.Count;
				for(int i=0; i< timersCount; i++ ) {
					CCTimer timer = element.timers[i];
					if(timer is CCTimerTargetSelector && selector == ((CCTimerTargetSelector)timer).selector){
						if(timer == element.currentTimer && !element.currentTimerSalvaged){
							element.currentTimerSalvaged = true;
						}
						element.timers.RemoveAt(i);
						if(element.timerIndex >= i)
							element.timerIndex --;
						if(element.timers.Count == 0){
							if(currentTarget == element)
								currentTargetSalvaged = true;
							else 
								removeHashElement(element);
						}
						return;
					}
				}
			}
			
			// Not Found
			//	NSLog(@"CCScheduler#unscheduleSelector:forTarget: selector not found: %@", selString);
		}
Пример #9
0
		public void scheduleBlockForKey(string key, System.Object owner, float interval, uint repeat, float delay, bool paused, TICK_IMP block)
		{
			NSUtils.Assert( block != null, "Argument block must be non-nil");
			NSUtils.Assert( owner != null, "Argument owner must be non-nil");
			
			tHashTimerEntry element = hashForTimers.HASH_FIND_INT(owner.GetHashCode());
			
			if (element == null) {
				element = new tHashTimerEntry ();
				element.target = owner;
				hashForTimers.HASH_ADD_INT(owner.GetHashCode(), element);
				
				// Is this the 1st element ? Then set the pause level to all the selectors of this target
				element.paused = paused;
				
			} else
				NSUtils.Assert( element.paused == paused, "CCScheduler. Trying to schedule a block with a pause value different than the target");
			
			
			if (element.timers == null)
				element.timers = new List<CCTimer> (10);
			else
			{
				var enumerator = element.timers.GetEnumerator();
				while (enumerator.MoveNext()) {
					CCTimer timer = enumerator.Current;
					if(timer is CCTimerBlock  && key == ((CCTimerBlock)timer).key) {
						CCDebug.Log("CCScheduler#scheduleBlock. Block already scheduled. Updating interval from: {0:0.0000} to {1:0.0000}", timer.interval, interval);
						timer.interval = interval;
						return;
					}
				}
			}
			
			CCTimerBlock timerBlock = new CCTimerBlock(owner, interval, key, block, repeat, delay);
			element.timers.Add(timerBlock);
		}
Пример #10
0
		/** The scheduled method will be called every 'interval' seconds.
		 If paused is YES, then it won't be called until it is resumed.
		 If 'interval' is 0, it will be called every frame, but if so, it recommended to use 'scheduleUpdateForTarget:' instead.
		 If the selector is already scheduled, then only the interval parameter will be updated without re-scheduling it again.
		 repeat lets the action be repeated repeat + 1 times, use kCCRepeatForever to let the action run continuously
		 delay is the amount of time the action will wait before it'll start

		 @since v0.99.3, repeat and delay added in v1.1
		 */
		public void schedule(TICK_IMP selector, System.Object target, float interval, uint repeat, bool paused, float delay=0){
			NSUtils.Assert( selector != null, "Argument selector must be non-nil");
			NSUtils.Assert( target != null, "Argument target must be non-nil");

			tHashTimerEntry element = hashForTimers.HASH_FIND_INT(target.GetHashCode());
			if (element == null) {
				element = new tHashTimerEntry ();
				element.target = target;
				hashForTimers.HASH_ADD_INT(target.GetHashCode(), element);

				// Is this the 1st element ? Then set the pause level to all the selectors of this target
				element.paused = paused;
			} else 
				NSUtils.Assert( element.paused == paused, "CCScheduler. Trying to schedule a selector with a pause value different than the target");


			if (element.timers == null)
				element.timers = new List<CCTimer> (10);
			else {
				var enumerator = element.timers.GetEnumerator();
				while (enumerator.MoveNext()) {
					CCTimer timer = enumerator.Current;
					if(timer is CCTimerTargetSelector && selector == ((CCTimerTargetSelector)timer).selector){
						CCDebug.Log("CCScheduler#scheduleSelector. Selector already scheduled. Updating interval from: {0:0.0000} to {1:0.0000}", timer.interval, interval);
						timer.interval = interval;
						return;
					}
				}
			}
			CCTimerTargetSelector timerSelector = new CCTimerTargetSelector(target, selector, interval, repeat, delay);
			element.timers.Add(timerSelector);
		}
Пример #11
0
 /**
  * Schedules a selector that runs only once, with a delay of 0 or larger
  */
 public void scheduleOnce(TICK_IMP selector, float delay)
 {
     schedule(selector, 0, 0, delay);
 }
Пример #12
0
        public void scheduleBlockForKey(string key, System.Object owner, float interval, uint repeat, float delay, bool paused, TICK_IMP block)
        {
            NSUtils.Assert(block != null, "Argument block must be non-nil");
            NSUtils.Assert(owner != null, "Argument owner must be non-nil");

            tHashTimerEntry element = hashForTimers.HASH_FIND_INT(owner.GetHashCode());

            if (element == null)
            {
                element        = new tHashTimerEntry();
                element.target = owner;
                hashForTimers.HASH_ADD_INT(owner.GetHashCode(), element);

                // Is this the 1st element ? Then set the pause level to all the selectors of this target
                element.paused = paused;
            }
            else
            {
                NSUtils.Assert(element.paused == paused, "CCScheduler. Trying to schedule a block with a pause value different than the target");
            }


            if (element.timers == null)
            {
                element.timers = new List <CCTimer> (10);
            }
            else
            {
                var enumerator = element.timers.GetEnumerator();
                while (enumerator.MoveNext())
                {
                    CCTimer timer = enumerator.Current;
                    if (timer is CCTimerBlock && key == ((CCTimerBlock)timer).key)
                    {
                        CCDebug.Log("CCScheduler#scheduleBlock. Block already scheduled. Updating interval from: {0:0.0000} to {1:0.0000}", timer.interval, interval);
                        timer.interval = interval;
                        return;
                    }
                }
            }

            CCTimerBlock timerBlock = new CCTimerBlock(owner, interval, key, block, repeat, delay);

            element.timers.Add(timerBlock);
        }
Пример #13
0
		public void unschedule(TICK_IMP selector){
			// explicit nil handling
			if (selector == null)
				return;
			
			_scheduler.unscheduleSelector(selector, this);
		}
Пример #14
0
		/**
		 Schedules a selector that runs only once, with a delay of 0 or larger
		*/
		public void scheduleOnce(TICK_IMP selector, float delay){
			schedule (selector, 0, 0, delay);
		}
Пример #15
0
		/**
		 repeat will execute the action repeat + 1 times, for a continues action use kCCRepeatForever
		 delay is the amount of time the action will wait before execution
		 */
		public void schedule(TICK_IMP selector, float interval=0, uint repeat=CCScheduler.kCCRepeatForever, float delay=0){
			NSUtils.Assert( selector != null, "Argument must be non-nil");
			NSUtils.Assert( FloatUtils.EB( interval , 0), "Arguemnt must be positive");
			

			_scheduler.schedule (selector, this, interval, repeat, !_isRunning, delay);
		}
Пример #16
0
		/** Initializes a timer with a target(owner), interval in seconds, repeat in number of times to repeat, delay in seconds and a block */
		public CCTimerBlock(System.Object owner, float seconds, string key, TICK_IMP block, uint repeat=CCScheduler.kCCRepeatForever, float delay=0){
			_block = block;
			_key = key;
			_target = owner;
			setupTimer (seconds, repeat, delay);
		}