⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 goengine.as

📁 jquery插件
💻 AS
📖 第 1 页 / 共 2 页
字号:
			}			items[ item ] = interval; // Tether item to original pulseint. Used in removeItem & setPaused(false).			if (!timers[ interval ]) {				addPulse( interval );				itemCounts[ interval ] = 1;			}			else {				itemCounts[ interval ] ++;			}			// Report IManageable instances to registered managers			if (item is IManageable) {				for each (var manager:IManager in managers)					manager.reserve( item as IManageable );			}			return true;		}				/**		 * Removes an item from the queue and removes its pulse timer if		 * the queue is depleted.		 * 		 * @param item		Any IUpdatable previously added that wishes 		 * 					to stop receiving update calls.		 * 							 * @return			Returns false if the item was not in the engine.		 * 		 * @see #addItem()		 */		public static function removeItem( item:IUpdatable ):Boolean		{			if (items[ item ]==null)				return false;			var interval: int = items[ item ];			if ( -- itemCounts[ interval ] == 0 ) {				removePulse( interval );				delete itemCounts[ interval ];			}			delete items[ item ];			delete addQueue[ item ]; // * see note following update			// Report IManageable item removal to registered managers.			if (item is IManageable) {				for each (var manager:IManager in managers) 					manager.release( item as IManageable );			}			return true;		}				/**		 * Removes all items and resets the engine, 		 * or removes just items running on a specific pulse.		 * 		 * @param pulseInterval		Optionally filter by a specific pulse 		 * 							such as ENTER_FRAME or a number of milliseconds.		 * @return					The number of items successfully removed.		 * @see #removeItem()		 */		public static function clear(pulseInterval:Number = NaN) : uint		{			var all:Boolean = (isNaN(pulseInterval));			var n:Number = 0;			for (var item:Object in items) {				if (all || items[ item ]==pulseInterval)					if (removeItem(item as IUpdatable)==true)						n++;			}			return n;		}				/**		 * Retrieves number of active items in the engine 		 * or active items running on a specific pulse.		 * 		 * @param pulseInterval		Optionally filter by a specific pulseInterval		 *							such as ENTER_FRAME or a number of milliseconds.		 * 		 * @return					Number of active items in the Engine.		 */		public static function getCount(pulseInterval:Number = NaN) : uint		{			if (!isNaN(pulseInterval))				return (itemCounts[pulseInterval]);			var n:Number = 0;			for each (var count: int in itemCounts)				n += count;			return n;		}				/**		 * @return			The paused state of engine.		 * @see #setPaused()		 */		public static function getPaused() : Boolean {			return paused;		}				/**		 * Pauses or resumes all animation globally by suspending processing,		 * and calls pause() or resume() on each item with those methods. 		 * 		 * <p>The return value only reflects how many items had pause() or resume()		 * called on them, but the GoEngine.getPaused() state will change if any 		 * pulses are suspended or resumed.</p>		 * 		 * @param pause				Pass false to resume if currently paused.		 * @param pulseInterval		Optionally filter by a specific pulse 		 * 							such as ENTER_FRAME or a number of milliseconds.		 * @return					The number of items on which a pause() or resume()		 * 							method was called (0 doesn't necessarily reflect		 * 							whether the GoEngine.getPaused() state changed, it		 * 							may simply indicate that no items had that method).		 * @see #resume()		 */		public static function setPaused(pause:Boolean=true, pulseInterval:Number = NaN) : uint		{			if (paused==pause) return 0;			var n:Number = 0;			var pulseChanged:Boolean = false;			var all:Boolean = (isNaN(pulseInterval));			var method:String = (pause ? "pause" : "resume");			for (var item:Object in items) {				var pulse:int = (items[item] as int);				if (all || pulse==pulseInterval) {					pulseChanged = (pulseChanged || (pause ? removePulse(pulse) : addPulse(pulse)));					// call pause or resume on the item if it has such a method.					if (item.hasOwnProperty(method)) {						if (item[method] is Function) {							item[method].apply(item);							n++;						}					}				}			}			if (pulseChanged)				paused = pause;			return n;		}				// -== Private Class Methods ==-				/**		 * Executes the update queue corresponding to the dispatcher's interval.		 * 		 * @param event			TimerEvent or Sprite ENTER_FRAME Event		 */		private static function update(event:Event) : void 		{			var currentTime:Number = getTimer();			var pulse:int = (event is TimerEvent ? ( event.target as Timer ).delay : ENTER_FRAME);			lockedPulses[ pulse ] = true;			var doLiveUpdate:Boolean = (liveManagers > 0);			var updated:Array;			if (doLiveUpdate) updated = []; // syncs the live manager list to items actually updated			for (var item:* in items) {				if (items[ item ]==pulse && !addQueue[ item ]) {					(item as IUpdatable).update(currentTime);					if (doLiveUpdate) updated.push(item);				}			}			lockedPulses[ pulse ] = false;			if (delayedPulses[ pulse ]) {				for (item in addQueue) 					delete addQueue[ item ];				delete delayedPulses[ pulse ];			}// updateAfterEvent() should not be needed as long as items follow tight-syncing instructions in GoItem.update() documentation.//			if (pulse!=ENTER_FRAME) (event as TimerEvent).updateAfterEvent();			if (doLiveUpdate)				for each (var manager:Object in managers)					if (manager is ILiveManager)						(manager as ILiveManager).onUpdate(pulse, updated, currentTime);  // * see note		}// * note: In one rare case that has not been reported yet but is theoretically possible, the 'updated' list // passed could contain already-released items. This could only happen if the item is removed & released // just after the main update cycle but before the the doLiveUpdate() routine runs. If you encounter this issue// please report it to the GoASAP mailing list, it's too involved to bother with before it's a problem.		/**		 * Creates new timers when a previously unused interval is specified,		 * and tracks the number of items associated with that interval.		 * 		 * @param pulse			The pulseInterval requested		 * @return				Whether a pulse was added		 */		private static function addPulse(pulse : int) : Boolean		{			if (pulse==ENTER_FRAME) {				if (!pulseSprite) {					timers[ENTER_FRAME] = pulseSprite = new Sprite();					pulseSprite.addEventListener(Event.ENTER_FRAME, update);				}				return true;			}			var t:Timer = timers[ pulse ] as Timer;			if (!t) {				t = timers[ pulse ] = new Timer(pulse);				(timers[ pulse ] as Timer).addEventListener(TimerEvent.TIMER, update);				t.start();				return true;			}			return false;		}				/**		 * Tracks whether a removed item was the last one using a timer 		 * and if so, removes that timer.		 * 		 * @param pulse			The pulseInterval corresponding to an item being removed.		 * @return				Whether a pulse was removed		 */		private static function removePulse(pulse : int) : Boolean		{			if (pulse==ENTER_FRAME) {				if (pulseSprite) {					pulseSprite.removeEventListener(Event.ENTER_FRAME, update);					delete timers[ ENTER_FRAME ];					pulseSprite = null;					return true;				}			}			var t:Timer = timers[ pulse ] as Timer;			if (t) {				t.stop();				t.removeEventListener(TimerEvent.TIMER, update);				delete timers[ pulse ];				return true;			}			return false;		}	}}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -