PageRenderTime 24ms CodeModel.GetById 21ms app.highlight 2ms RepoModel.GetById 1ms app.codeStats 0ms

/Tweener.cs

http://github.com/dabrorius/MonoPunk
C# | 119 lines | 65 code | 11 blank | 43 comment | 18 complexity | 0d34886f52f7aec71c51fbc99262162d MD5 | raw file
  1namespace Dabrorius.MonoPunk
  2{
  3    /**
  4     * Updateable Tween container.
  5     */
  6    class Tweener
  7    {
  8        /**
  9         * Persistent Tween type, will stop when it finishes.
 10         */
 11        public const uint PERSIST = 0;
 12        /**
 13         * Looping Tween type, will restart immediately when it finishes.
 14         */
 15        public const uint LOPPING = 1;
 16        /**
 17         * Oneshot Tween type, will stop and remove itself from its core container when it finishes.
 18         */
 19        public const uint ONESHOT = 2;
 20
 21        /**
 22         * If the Tweener should update.
 23         */
 24        public bool active = true;
 25
 26        /**
 27         * If the Tweener should clear on removal. For Entities, this is when they are
 28         * removed from a World, and for World this is when the active World is switched.
 29         */
 30        public bool autoClear = false;
 31
 32        /**
 33         * Constructor.
 34         */
 35        public  Tweener()
 36        {
 37     
 38        }
 39
 40        /**
 41         * Updates the Tween container.
 42         */
 43        public void update()
 44        { 
 45        
 46        }
 47
 48        /**
 49         * Adds a new Tween.
 50         * @param	t			The Tween to add.
 51         * @param	start		If the Tween should call start() immediately.
 52         * @return	The added Tween.
 53         */
 54        public Tween addTween(Tween t, bool start = false)
 55        {
 56            if (t._parent != null) throw new System.ArgumentException("Cannot add a Tween object more than once.");
 57            t._parent = this;
 58            t._next = _tween;
 59            if (_tween != null) _tween._prev = t;
 60            _tween = t;
 61            if (start) _tween.start();
 62            return t;
 63        }
 64        
 65        /**
 66         * Removes a Tween.
 67         * @param	t		The Tween to remove.
 68         * @return	The removed Tween.
 69         */
 70        public Tween removeTween(Tween t)
 71        {
 72            if (t._parent != this) throw new System.ArgumentException("Core object does not contain Tween.");
 73            if (t._next != null) t._next._prev = t._prev;
 74            if (t._prev != null) t._prev._next = t._next;
 75            else _tween = t._next;
 76            t._next = t._prev = null;
 77            t._parent = null;
 78            t.active = false;
 79            return t;        
 80        }
 81
 82        /**
 83         * Removes all Tweens.
 84         */
 85        public void clearTweens()
 86        {
 87            Tween t = _tween;
 88            Tween n;
 89            while (t != null)
 90            {
 91                n = t._next;
 92                removeTween(t);
 93                t = n;
 94            }
 95        }
 96
 97        /** 
 98		 * Updates all contained tweens.
 99		 */
100        public void updateTweens()
101        {
102            Tween t = _tween;
103            Tween n;
104            while (t != null)
105            {
106                n = t._next;
107                if (t.active)
108                {
109                    t.update();
110                    if (t._finish) t.finish();
111                }
112                t = n;
113            }
114        }
115
116        // List information.
117        /** @private */ internal Tween _tween;
118    }
119}