Just a helper structure for the FlxSprite animation system.
Beispiel #1
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
        }
Beispiel #2
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;
 }
Beispiel #3
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;
            */
        }
Beispiel #4
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 + "\"");
        }