The camera class is used to display the game's visuals in the Flash player. By default one camera is created automatically, that is the same size as the Flash player. You can add more cameras or even replace the main camera using utilities in FlxG.
Inheritance: FlxBasic
Ejemplo n.º 1
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);
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Check and see if this object is currently on screen.
        /// Differs from <code>FlxObject</code>'s implementation
        /// in that it takes the actual graphic into account,
        /// not just the hitbox or bounding box or whatever.
        /// </summary>
        /// <param name="camera">Specify which game camera you want.  If null getScreenXY() will just grab the first global camera.</param>
        /// <returns>Whether the object is on screen or not.</returns>
        override public bool onScreen(FlxCamera camera = null)
        {
            if (camera == null)
            {
                camera = FlxG.camera;
            }

            getScreenXY(_tagPoint, camera);
            _tagPoint.X = _tagPoint.X - Offset.X;
            _tagPoint.Y = _tagPoint.Y - Offset.Y;

            /*
             * if (((angle == 0) || (_bakedRotation > 0)) && (scale.x == 1) && (scale.y == 1))
             *  return ((_point.x + frameWidth > 0) && (_point.x < Camera.width) && (_point.y + frameHeight > 0) && (_point.y < Camera.height));
             */

            float halfWidth  = FrameWidth / 2;
            float halfHeight = FrameHeight / 2;
            float absScaleX  = (Scale.X > 0) ? Scale.X : -Scale.X;
            float absScaleY  = (Scale.Y > 0) ? Scale.Y : -Scale.Y;
            float radius     = (float)Math.Sqrt((halfWidth * halfWidth) + (halfHeight * halfHeight)) * ((absScaleX >= absScaleY) ? absScaleX : absScaleY);

            _tagPoint.X = _tagPoint.X + halfWidth;
            _tagPoint.Y = _tagPoint.Y + halfHeight;
            return((_tagPoint.X + radius > 0) && (_tagPoint.X - radius < camera.Width) && (_tagPoint.Y + radius > 0) && (_tagPoint.Y - radius < camera.Height));
        }
Ejemplo n.º 3
0
        /// <summary>
        /// Checks to see if a point in 2D world space overlaps this <code>FlxSprite</code> object's current displayed pixels.
        /// This check is ALWAYS made in screen space, and always takes scroll factors into account.
        /// </summary>
        /// <param name="point">The point in world space you want to check.</param>
        /// <param name="mask">Used in the pixel hit test to determine what counts as solid.</param>
        /// <param name="camera">Specify which game camera you want.  If null getScreenXY() will just grab the first global camera.</param>
        /// <returns></returns>
        public bool pixelOverlapPoint(FlxPoint point, uint mask = 0xFF, FlxCamera camera = null)
        {
            throw new NotImplementedException();

            /*
             *          if(Camera == null)
             *                  Camera = FlxG.camera;
             *          getScreenXY(_point,Camera);
             *          _point.x = _point.x - offset.x;
             *          _point.y = _point.y - offset.y;
             *          _flashPoint.x = (Point.x - Camera.scroll.x) - _point.x;
             *          _flashPoint.y = (Point.y - Camera.scroll.y) - _point.y;
             *          return framePixels.hitTest(_flashPointZero,Mask,_flashPoint);
             */
        }
Ejemplo n.º 4
0
        /// <summary>
        /// While this doesn't override <code>FlxBasic.DrawDebug()</code>, the behavior is very similar.
        /// Based on this path data, it draws a simple lines-and-boxes representation of the path
        /// if the visual debug mode was toggled in the debugger overlay. You can use <code>DebugColor</code>
        /// and <code>DebugScrollFactor</code> to control the path's appearance.
        /// </summary>
        /// <param name="camera">The camera object the path will draw to.</param>
        public void DrawDebug(FlxCamera camera)
        {
            throw new NotImplementedException();

            /*
             *          if(nodes.length <= 0)
             *                  return;
             *          if(Camera == null)
             *                  Camera = FlxG.camera;
             *
             *          //Set up our global flash graphics object to draw out the path
             *          var gfx:Graphics = FlxG.flashGfx;
             *          gfx.clear();
             *
             *          //Then fill up the object with node and path graphics
             *          var node:FlxPoint;
             *          var nextNode:FlxPoint;
             *          var i:uint = 0;
             *          var l:uint = nodes.length;
             *          while(i < l)
             *          {
             *                  //get a reference to the current node
             *                  node = nodes[i] as FlxPoint;
             *
             *                  //find the screen position of the node on this camera
             *                  _point.x = node.x - int(Camera.scroll.x*debugScrollFactor.x); //copied from getScreenXY()
             *                  _point.y = node.y - int(Camera.scroll.y*debugScrollFactor.y);
             *                  _point.x = int(_point.x + ((_point.x > 0)?0.0000001:-0.0000001));
             *                  _point.y = int(_point.y + ((_point.y > 0)?0.0000001:-0.0000001));
             *
             *                  //decide what color this node should be
             *                  var nodeSize:uint = 2;
             *                  if((i == 0) || (i == l-1))
             *                          nodeSize *= 2;
             *                  var nodeColor:uint = debugColor;
             *                  if(l > 1)
             *                  {
             *                          if(i == 0)
             *                                  nodeColor = FlxG.GREEN;
             *                          else if(i == l-1)
             *                                  nodeColor = FlxG.RED;
             *                  }
             *
             *                  //draw a box for the node
             *                  gfx.beginFill(nodeColor,0.5);
             *                  gfx.lineStyle();
             *                  gfx.drawRect(_point.x-nodeSize*0.5,_point.y-nodeSize*0.5,nodeSize,nodeSize);
             *                  gfx.endFill();
             *
             *                  //then find the next node in the path
             *                  var linealpha:Number = 0.3;
             *                  if(i < l-1)
             *                          nextNode = nodes[i+1];
             *                  else
             *                  {
             *                          nextNode = nodes[0];
             *                          linealpha = 0.15;
             *                  }
             *
             *                  //then draw a line to the next node
             *                  gfx.moveTo(_point.x,_point.y);
             *                  gfx.lineStyle(1,debugColor,linealpha);
             *                  _point.x = nextNode.x - int(Camera.scroll.x*debugScrollFactor.x); //copied from getScreenXY()
             *                  _point.y = nextNode.y - int(Camera.scroll.y*debugScrollFactor.y);
             *                  _point.x = int(_point.x + ((_point.x > 0)?0.0000001:-0.0000001));
             *                  _point.y = int(_point.y + ((_point.y > 0)?0.0000001:-0.0000001));
             *                  gfx.lineTo(_point.x,_point.y);
             *
             *                  i++;
             *          }
             *
             *          //then stamp the path down onto the game buffer
             *          Camera.buffer.draw(FlxG.flashGfxSprite);
             */
        }
Ejemplo n.º 5
0
 /// <summary>
 /// Override this function to draw custom "debug mode" graphics to the
 /// specified camera while the debugger's visual mode is toggled on.
 /// </summary>
 /// <param name="camera">Which camera to draw the debug visuals to.</param>
 public virtual void drawDebug(FlxCamera camera = null)
 {
 }
Ejemplo n.º 6
0
 /// <summary>
 /// Override this function to draw custom "debug mode" graphics to the
 /// specified camera while the debugger's visual mode is toggled on.
 /// </summary>
 /// <param name="camera">Which camera to draw the debug visuals to.</param>
 public virtual void drawDebug(FlxCamera camera = null)
 {
 }
Ejemplo n.º 7
0
        /// <summary>
        /// Check and see if this object is currently on screen.
        /// Differs from <code>FlxObject</code>'s implementation
        /// in that it takes the actual graphic into account,
        /// not just the hitbox or bounding box or whatever.
        /// </summary>
        /// <param name="camera">Specify which game camera you want.  If null getScreenXY() will just grab the first global camera.</param>
        /// <returns>Whether the object is on screen or not.</returns>
        public override bool onScreen(FlxCamera camera = null)
        {
            if (camera == null)
            {
                camera = FlxG.camera;
            }

            getScreenXY(_tagPoint, camera);
            _tagPoint.X = _tagPoint.X - Offset.X;
            _tagPoint.Y = _tagPoint.Y - Offset.Y;

            /*
            if (((angle == 0) || (_bakedRotation > 0)) && (scale.x == 1) && (scale.y == 1))
                return ((_point.x + frameWidth > 0) && (_point.x < Camera.width) && (_point.y + frameHeight > 0) && (_point.y < Camera.height));
            */

            float halfWidth = FrameWidth / 2;
            float halfHeight = FrameHeight / 2;
            float absScaleX = (Scale.X > 0) ? Scale.X : -Scale.X;
            float absScaleY = (Scale.Y > 0) ? Scale.Y : -Scale.Y;
            float radius = (float)Math.Sqrt((halfWidth * halfWidth) + (halfHeight * halfHeight)) * ((absScaleX >= absScaleY) ? absScaleX : absScaleY);
            _tagPoint.X = _tagPoint.X + halfWidth;
            _tagPoint.Y = _tagPoint.Y + halfHeight;
            return ((_tagPoint.X + radius > 0) && (_tagPoint.X - radius < camera.Width) && (_tagPoint.Y + radius > 0) && (_tagPoint.Y - radius < camera.Height));
        }
Ejemplo n.º 8
0
        /// <summary>
        /// Checks to see if a point in 2D world space overlaps this <code>FlxSprite</code> object's current displayed pixels.
        /// This check is ALWAYS made in screen space, and always takes scroll factors into account.
        /// </summary>
        /// <param name="point">The point in world space you want to check.</param>
        /// <param name="mask">Used in the pixel hit test to determine what counts as solid.</param>
        /// <param name="camera">Specify which game camera you want.  If null getScreenXY() will just grab the first global camera.</param>
        /// <returns></returns>
        public bool pixelOverlapPoint(FlxPoint point, uint mask = 0xFF, FlxCamera camera = null)
        {
            throw new NotImplementedException();

            /*
            if(Camera == null)
                Camera = FlxG.camera;
            getScreenXY(_point,Camera);
            _point.x = _point.x - offset.x;
            _point.y = _point.y - offset.y;
            _flashPoint.x = (Point.x - Camera.scroll.x) - _point.x;
            _flashPoint.y = (Point.y - Camera.scroll.y) - _point.y;
            return framePixels.hitTest(_flashPointZero,Mask,_flashPoint);
            */
        }
Ejemplo n.º 9
0
        /// <summary>
        /// While this doesn't override <code>FlxBasic.DrawDebug()</code>, the behavior is very similar.
        /// Based on this path data, it draws a simple lines-and-boxes representation of the path
        /// if the visual debug mode was toggled in the debugger overlay. You can use <code>DebugColor</code>
        /// and <code>DebugScrollFactor</code> to control the path's appearance.
        /// </summary>
        /// <param name="camera">The camera object the path will draw to.</param>
        public void DrawDebug(FlxCamera camera)
        {
            throw new NotImplementedException();

            /*
            if(nodes.length <= 0)
                return;
            if(Camera == null)
                Camera = FlxG.camera;

            //Set up our global flash graphics object to draw out the path
            var gfx:Graphics = FlxG.flashGfx;
            gfx.clear();

            //Then fill up the object with node and path graphics
            var node:FlxPoint;
            var nextNode:FlxPoint;
            var i:uint = 0;
            var l:uint = nodes.length;
            while(i < l)
            {
                //get a reference to the current node
                node = nodes[i] as FlxPoint;

                //find the screen position of the node on this camera
                _point.x = node.x - int(Camera.scroll.x*debugScrollFactor.x); //copied from getScreenXY()
                _point.y = node.y - int(Camera.scroll.y*debugScrollFactor.y);
                _point.x = int(_point.x + ((_point.x > 0)?0.0000001:-0.0000001));
                _point.y = int(_point.y + ((_point.y > 0)?0.0000001:-0.0000001));

                //decide what color this node should be
                var nodeSize:uint = 2;
                if((i == 0) || (i == l-1))
                    nodeSize *= 2;
                var nodeColor:uint = debugColor;
                if(l > 1)
                {
                    if(i == 0)
                        nodeColor = FlxG.GREEN;
                    else if(i == l-1)
                        nodeColor = FlxG.RED;
                }

                //draw a box for the node
                gfx.beginFill(nodeColor,0.5);
                gfx.lineStyle();
                gfx.drawRect(_point.x-nodeSize*0.5,_point.y-nodeSize*0.5,nodeSize,nodeSize);
                gfx.endFill();

                //then find the next node in the path
                var linealpha:Number = 0.3;
                if(i < l-1)
                    nextNode = nodes[i+1];
                else
                {
                    nextNode = nodes[0];
                    linealpha = 0.15;
                }

                //then draw a line to the next node
                gfx.moveTo(_point.x,_point.y);
                gfx.lineStyle(1,debugColor,linealpha);
                _point.x = nextNode.x - int(Camera.scroll.x*debugScrollFactor.x); //copied from getScreenXY()
                _point.y = nextNode.y - int(Camera.scroll.y*debugScrollFactor.y);
                _point.x = int(_point.x + ((_point.x > 0)?0.0000001:-0.0000001));
                _point.y = int(_point.y + ((_point.y > 0)?0.0000001:-0.0000001));
                gfx.lineTo(_point.x,_point.y);

                i++;
            }

            //then stamp the path down onto the game buffer
            Camera.buffer.draw(FlxG.flashGfxSprite);
            */
        }
Ejemplo n.º 10
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;
        }