//private GameScreen _lastScreen; /// <summary> /// ScreenManager constructor. Automatically adds itself to game components /// </summary> /// <param name="game">Parent game of this ScreenManager</param> public ScreenManager(Game game) : base(game) { _game=game; _game.Components.Add(this); _fadeColour=new Color(0,0,0,_blackAlpha); _fadeTimer=new Timer(25,0,UpdateFade); _fadeTimer.Enabled=false; Timers.Add(_fadeTimer); }
public Animation(GameObject parent,int width,int height,bool useTimer) { _texture=parent._texture; _textureRect=new Rectangle(0,0,_texture.Width,_texture.Height); _displayRect=new Rectangle(0,0,width,height); _cols=_texture.Width/width; _rows=_texture.Height/height; _totalFrames=_cols*_rows; _parent=parent; _currentStage=new AnimationStage(0,_totalFrames-1,true,0,false); _parent._srcRect=_displayRect; _currentStageIndex=0; _useTimer=useTimer; if (_useTimer){ _timer=new Timer(DEFAULT_FRAME_DELAY,0,Animate,this); _timerIndex=Timers.Add(_timer); } }
/// <summary> /// Remove a timer /// </summary> /// <param name="timer">Timer to remove</param> public static void Remove(Timer timer) { for (int i=0;i<_timers.Length;i++) if (_timers[i]==timer) { if (_timersByID.ContainsKey(_timers[i].TimerID)) _timersByID.Remove(_timers[i].TimerID); _timers[i]=null; return; } }
/// <summary> /// Add a timer /// </summary> /// <param name="timer">Timer to add</param> /// <returns>New timer ID</returns> public static int Add(Timer timer) { int i; for (i=0;i<_timers.Length;i++) if (_timers[i]==null) { _timers[i]=timer; break; } System.Diagnostics.Debug.Assert(i!=_timers.Length); if (i<_timers.Length) { _timersByID[timer.TimerID]=i; return timer.TimerID; } else return -1; }
/// <summary> /// Add a timer /// </summary> /// <param name="Interval">Timer's interval</param> /// <param name="Reps">Number of times to repeat this timer before removal</param> /// <param name="Tick">Method to execute each tick</param> /// <param name="obj">Parent object - useful for posession checking and debugging</param> /// <returns>New timer ID</returns> public static int Add(int Interval,int Reps,Timer.OnTick Tick, object obj) { return Add(new Timer(Interval,Reps,Tick,obj)); }