This is the base class for most of the display objects (FlxSprite, FlxText, etc). It includes some basic attributes about game objects, including retro-style flickering, basic state information, sizes, scrolling, and basic physics and motion.
Inheritance: FlxBasic
示例#1
0
 /// <summary>
 /// Call this function if you want this sound's volume to change
 /// based on distance from a particular FlxCore object.
 /// </summary>
 /// <param name="x">The X position of the sound.</param>
 /// <param name="y">The Y position of the sound.</param>
 /// <param name="target">The object you want to track.</param>
 /// <param name="radius">The maximum distance this sound can travel.</param>
 /// <param name="pan">Whether the sound should pan in addition to the volume changes (default: true).</param>
 /// <returns>This FlxSound instance (nice for chaining stuff together, if you're into that).</returns>
 public FlxSound proximity(float x, float y, FlxObject target, float radius, bool pan = true)
 {
     this.x = x;
     this.y = y;
     _target = target;
     _radius = radius;
     _pan = pan;
     return this;
 }
示例#2
0
        /// <summary>
        /// An internal function for clearing all the variables used by sounds.
        /// </summary>
        protected void createSound()
        {
            destroy();

            x = 0;
            y = 0;
            _sound = null;
            _position = 0;
            _volume = 1.0f;
            _volumeAdjust = 1.0f;
            _looped = false;
            _target = null;
            _radius = 0;
            _pan = false;
            _fadeOutTimer = 0;
            _fadeOutTotal = 0;
            _pauseOnFadeOut = false;
            _fadeInTimer = 0;
            _fadeInTotal = 0;
            Exists = false;
            Active = false;
            Visible = false;
            name = null;
            artist = null;
            amplitude = 0;
            amplitudeLeft = 0;
            amplitudeRight = 0;
            autoDestroy = false;
        }
示例#3
0
        /// <summary>
        /// Clean up memory.
        /// </summary>
        public override void destroy()
        {
            kill();

            if (_sound != null)
            {
                _sound.Dispose();
            }
            _sound = null;
            _target = null;
            name = null;
            artist = null;

            base.destroy();
        }
示例#4
0
        /// <summary>
        /// Tells this camera object what <code>FlxObject</code> to track.
        /// </summary>
        /// <param name="target">The object you want the camera to track. Set to null to not follow anything.</param>
        /// <param name="style">Leverage one of the existing "deadzone" presets.  If you use a custom deadzone, ignore this parameter and manually specify the deadzone after calling <code>follow()</code>.</param>
        public void follow(FlxObject target, uint style = StyleLockon)
        {
            Target = target;
            float helper;

            switch (style)
            {
                case StylePlatformer:
                    float w = Width / 8;
                    float h = Height / 3;
                    Deadzone = new FlxRect((Width - w) / 2, (Height - h) / 2 - h * 0.25f, w, h);
                    break;

                case StyleTopdown:
                    helper = FlxU.max(Width, Height) / 4;
                    Deadzone = new FlxRect((Width - helper) / 2, (Height - helper) / 2, helper, helper);
                    break;

                case StyleTopdownTight:
                    helper = FlxU.max(Width, Height) / 8;
                    Deadzone = new FlxRect((Width - helper) / 2, (Height - helper) / 2, helper, helper);
                    break;

                case StyleLockon:
                    break;

                case StyleLoose:
                    Deadzone = new FlxRect(0, 0, Width, Height);
                    break;

                default:
                    Deadzone = null;
                    break;
            }
        }
示例#5
0
        /// <summary>
        /// Clean up memory.
        /// </summary>
        public override void destroy()
        {
            screen.destroy();
            screen = null;
            Target = null;
            Scroll = null;
            Deadzone = null;
            Bounds = null;
            Buffer = null;
            //_flashBitmap = null;
            //_flashRect = null;
            //_flashPoint = null;
            fxFlashComplete = null;
            fxFadeComplete = null;
            fxShakeComplete = null;
            fxShakeOffset = null;
            //_fill = null;

            base.destroy();
        }
示例#6
0
        /// <summary>
        /// Copy the bounds, focus object, and deadzone info from an existing camera.
        /// </summary>
        /// <param name="camera">The camera you want to copy from.</param>
        /// <returns>A reference to this <code>FlxCamera</code> object.</returns>
        public FlxCamera copyFrom(FlxCamera camera)
        {
            if (camera.Bounds == null)
            {
                this.Bounds = null;
            }
            else
            {
                if (this.Bounds == null)
                {
                    this.Bounds = new FlxRect();
                }
                this.Bounds.copyFrom(camera.Bounds);
            }

            this.Target = camera.Target;

            if (this.Target != null)
            {
                if (camera.Deadzone == null)
                {
                    this.Deadzone = null;
                }
                else
                {
                    if (this.Deadzone == null)
                    {
                        this.Deadzone = new FlxRect();
                    }
                    this.Deadzone.copyFrom(camera.Deadzone);
                }
            }

            return this;
        }
示例#7
0
        /// <summary>
        /// Instantiates a new camera at the specified location, with the specified size and zoom level.
        /// </summary>
        /// <param name="x">X location of the camera's display in pixels. Uses native, 1:1 resolution, ignores zoom.</param>
        /// <param name="y">Y location of the camera's display in pixels. Uses native, 1:1 resolution, ignores zoom.</param>
        /// <param name="width">The width of the camera display in pixels.</param>
        /// <param name="height">The height of the camera display in pixels.</param>
        /// <param name="zoom">The initial zoom level of the camera. A zoom level of 2 will make all pixels display at 2x resolution.</param>
        public FlxCamera(float x, float y, int width, int height, float zoom = 0)
            : base()
        {
            X = x;
            Y = y;
            Width = width;
            Height = height;
            Target = null;
            Deadzone = null;
            Scroll = new FlxPoint();
            _point = new FlxPoint();
            Bounds = null;
            screen = new FlxSprite();
            screen.makeGraphic((uint) width, (uint) height, new Color(0, 0, 0, 0));
            screen.setOriginToCorner();
            //Buffer = screen.Pixels;
            BgColor = FlxG.bgColor;

            _color = Color.White;
            //_color = 0xffffffff;

            /*
            _flashBitmap = new Bitmap(buffer);
            _flashBitmap.x = -width*0.5;
            _flashBitmap.y = -height*0.5;
            _flashSprite = new Sprite();
            */

            // flx# - ?
            // zoom = Zoom; //sets the scale of flash sprite, which in turn loads flashoffset values

            /*
            _flashOffsetX = width*0.5*zoom;
            _flashOffsetY = height*0.5*zoom;
            _flashSprite.x = x + _flashOffsetX;
            _flashSprite.y = y + _flashOffsetY;
            _flashSprite.addChild(_flashBitmap);
            _flashRect = new Rectangle(0,0,width,height);
            _flashPoint = new Point();
            */

            fxFlashColor = Color.Black;
            fxFlashDuration = 0.0f;
            fxFlashComplete = null;
            fxFlashAlpha = 0.0f;

            fxFadeColor = Color.Black;
            fxFadeDuration = 0.0f;
            fxFadeComplete = null;
            fxFadeAlpha = 0.0f;

            fxShakeIntensity = 0.0f;
            fxShakeDuration = 0.0f;
            fxShakeComplete = null;
            fxShakeOffset = new FlxPoint();
            fxShakeDirection = 0;

            //_fill = new BitmapData(width,height,true,0);

            // flx#
            //DefaultZoom = 1.0f;
            rotating = 0.0f;
            Zoom = zoom;
            FlashSprite = new FlxObject();
            //BgColor = Color.Black;

            _fxHelperTexture = new Texture2D(FlxS.GraphicsDevice, 1, 1, false, SurfaceFormat.Color);
            _fxHelperTexture.SetData(new[] { Color.White });

            _fillTexture = new Texture2D(FlxS.GraphicsDevice, 1, 1, false, SurfaceFormat.Color);
            _fillTexture.SetData(new[] { Color.White });

            UpdateHelpers();
        }