Example #1
0
        /// <summary>
        /// Plays an existing animation (e.g. "run").
        /// If you call an animation that is already playing it will be ignored.
        /// </summary>
        /// <param name="animName">The string name of the animation you want to play.</param>
        /// <param name="force">Whether to force the animation to restart.</param>
        public void play(String animName, Boolean force = false)
        {
            if (!force && (_curAnim != null) && (animName == _curAnim.Name) && (_curAnim.Looped || !Finished))
            {
                return;
            }
            _curFrame   = 0;
            _curIndex   = 0;
            _frameTimer = 0;

            foreach (FlxAnim animation in _animations)
            {
                if (animation.Name.Equals(animName))
                {
                    _curAnim = animation;

                    if (_curAnim.Delay <= 0)
                    {
                        Finished = true;
                    }
                    else
                    {
                        Finished = false;
                    }

                    _curIndex = _curAnim.Frames[_curFrame];
                    Dirty     = true;
                    return;
                }
            }

            FlxG.log("WARNING: No animation called \"" + animName + "\"");
        }
Example #2
0
        public override void destroy()
        {
            // flx# - can animations in _animations be null?

            /*
             * if(_animations != null)
             *          {
             *                  FlxAnim a;
             *                  int i = 0;
             *                  int l = _animations.Count;
             *                  while(i < l)
             *                  {
             *                          a = _animations[i++];
             *                          if(a != null)
             *                                  a.destroy();
             *                  }
             *                  _animations = null;
             *          }
             */

            if (_animations != null)
            {
                foreach (FlxAnim animation in _animations)
                {
                    animation.destroy();
                }
            }

            _flashPoint     = null;
            _flashRect      = null;
            _flashRect2     = null;
            _flashPointZero = null;

            Offset = null;
            Origin = null;
            Scale  = null;

            _curAnim = null;
            //_matrix = null; // flx# - matrix is a struct
            _callback = null;
            //_framePixels = null; // flx# - unused
        }
Example #3
0
        private void constructor(float X, float Y, Texture2D SimpleGraphic)
        {
            x = X;
            y = Y;

            _flashRect = new Rectangle();
            _flashRect2 = new Rectangle();
            _flashPointZero = new Point();
            offset = new Point();

            scale = 1f;
            _alpha = 1;
            _color = Color.White;
            blend = null;
            antialiasing = false;

            finished = false;
            facing = Flx2DFacing.NotUsed;
            _animations = new List<FlxAnim>();
            _flipped = 0;
            _curAnim = null;
            _curFrame = 0;
            _caf = 0;
            _frameTimer = 0;

            //_mtx = new Matrix();
            _callback = null;
            //if (_gfxSprite == null)
            //{
            //    _gfxSprite = new Sprite();
            //    _gfx = _gfxSprite.graphics;
            //}

            if (SimpleGraphic == null)
                createGraphic(8, 8, color);
            else
                loadGraphic(SimpleGraphic);
        }
Example #4
0
 /**
  * Tell the sprite to change to a random frame of animation
  * Useful for instantiating particles or other weird things.
  */
 public void randomFrame()
 {
     _curAnim = null;
     _caf = (int)(FlxU.random()*(_tex.Width/frameWidth));
     calcFrame();
 }
Example #5
0
 /**
  * Plays an existing animation (e.g. "run").
  * If you call an animation that is already playing it will be ignored.
  *
  * @param	AnimName	The string name of the animation you want to play.
  * @param	Force		Whether to force the animation to restart.
  */
 public void play(string AnimName, bool Force)
 {
     if(!Force && (_curAnim != null) && (AnimName == _curAnim.name)) return;
     _curFrame = 0;
     _caf = 0;
     _frameTimer = 0;
     for(int i = 0; i < _animations.Count; i++)
     {
         if(_animations[i].name == AnimName)
         {
             _curAnim = _animations[i];
             if (_curAnim.delay <= 0)
                 finished = true;
             else
                 finished = false;
             _caf = _curAnim.frames[_curFrame];
             calcFrame();
             return;
         }
     }
 }
Example #6
0
        /// <summary>
        /// Creates a white 8x8 square <code>FlxSprite</code> at the specified position.
        /// Optionally can load a simple, one-frame graphic instead.
        /// </summary>
        /// <param name="x">The initial X position of the sprite.</param>
        /// <param name="y">The initial Y position of the sprite.</param>
        /// <param name="graphic">The graphic you want to display (OPTIONAL - for simple stuff only, do NOT use for animated images!).</param>
        public FlxSprite(float x = 0, float y = 0, Texture2D graphic = null)
            : base(x, y)
        {
            Health = 1;

            _flashPoint     = new FlxPoint();
            _flashRect      = new FlxRect();
            _flashRect2     = new FlxRect();
            _flashPointZero = new FlxPoint(0, 0);
            Offset          = new FlxPoint();
            Origin          = new FlxPoint();

            Scale        = new FlxPoint(1, 1);
            Alpha        = 1;
            Color        = Color.White;
            Blend        = null;
            AntiAliasing = false;
            Cameras      = null;

            Finished    = false;
            _facing     = Right;
            _animations = new List <FlxAnim>();
            _flipped    = 0;
            _curAnim    = null;
            _curFrame   = 0;
            _curIndex   = 0;
            _frameTimer = 0;

            _matrix   = new Matrix();
            _callback = null;

            if (graphic == null)
            {
                graphic = ImgDefault;
            }

            loadGraphic(graphic);

            // flx# stuff
            Angle  = 0f;
            camX   = camY = 0;
            oX     = x;
            oY     = y;
            moving = false;

            /*
             * Scale = new FlxPoint(1.0f, 1.0f);
             * Offset = new FlxPoint();
             * Origin = new FlxPoint();
             * alpha = 1.0f;
             * _color = Color.White * alpha;
             *
             * _animations = new List<FlxAnim>();
             * _animated = false;
             *
             * Finished = false;
             * _facing = Right;
             * _flipped = 0;
             * _curAnim = null;
             * _curFrame = 0;
             * _curIndex = 0;
             * _frameTimer = 0;
             *
             * _callback = null;
             * _matrix = new Matrix();
             *
             * if (graphic == null)
             *  graphic = ImgDefault;
             * loadGraphic(graphic);
             *
             * Angle = 0f;
             *
             * camX = camY = 0;
             * oX = x;
             * oY = y;
             *
             * moving = false;
             */
        }
Example #7
0
 /// <summary>
 /// Tell the sprite to change to a random frame of animation
 /// Useful for instantiating particles or other weird things.
 /// </summary>
 public void randomFrame()
 {
     _curAnim  = null;
     _curIndex = (int)(FlxG.random() * (_pixels.Width / FrameWidth));
     Dirty     = true;
 }