getScreenXY() public method

Call this to figure out the on-screen position of the object
public getScreenXY ( FlxPoint Point = null, FlxCamera Camera = null ) : FlxPoint
Point FlxPoint Take a FlxPoint object and assign the post-scrolled X and Y values of this object to it
Camera FlxCamera Which Camera - currently only one exists
return FlxPoint
Beispiel #1
0
        /// <summary>
        /// Checks to see if this FlxObject were located at the given position
        /// </summary>
        /// <param name="X">X position you want to check</param>
        /// <param name="Y">Y position you want to check</param>
        /// <param name="ObjectOrGroup">The object or group being tested</param>
        /// <param name="InScreenSpace">Whether to take scroll factors into account.</param>
        /// <param name="Camera">Which Camera - currently only one exists</param>
        /// <returns></returns>
        public virtual bool overlapsAt(float X, float Y, FlxBasic ObjectOrGroup, bool InScreenSpace = false, FlxCamera Camera = null)
        {
            if (ObjectOrGroup is FlxGroup)
            {
                bool results = false;
                int  i = 0; List <FlxBasic> members = new List <FlxBasic>();
                members = (ObjectOrGroup as FlxGroup).members;
                uint length = (uint)members.Count;
                while (i < length)
                {
                    if (overlapsAt(X, Y, members[i++], InScreenSpace, Camera))
                    {
                        results = true;
                    }
                }
                return(results);
            }

            if (ObjectOrGroup is FlxTilemap)
            {
                FlxTilemap tilemap = ObjectOrGroup as FlxTilemap;
                return(tilemap.overlapsAt(tilemap.x - (X - x), tilemap.y - (Y - y), this, InScreenSpace, Camera));
            }

            FlxObject Object = ObjectOrGroup as FlxObject;

            if (!InScreenSpace)
            {
                return((Object.x + Object.width > X) && (Object.x < X + width) &&
                       (Object.y + Object.height > Y) && (Object.y < Y + height));
            }

            if (Camera == null)
            {
                Camera = FlxG.camera;
            }
            FlxPoint objectScreenPos = Object.getScreenXY(null, Camera);

            _point.x  = X - Camera.scroll.x * scrollFactor.x;
            _point.y  = Y - Camera.scroll.y * scrollFactor.y;
            _point.x += (_point.x > 0) ? 0.0000001f : -0.0000001f;
            _point.y += (_point.y > 0) ? 0.0000001f : -0.0000001f;

            return((objectScreenPos.x + Object.width > _point.x) && (objectScreenPos.x < _point.x + width) &&
                   (objectScreenPos.y + Object.height > _point.y) && (objectScreenPos.y < _point.y + height));
        }
Beispiel #2
0
        /// <summary>
        /// Checks to see if some FlxObject overlaps this FlxObject or FlxGroup.
        /// If the group has a LOT of things in it, it might be faster to use <code>FlxG.ovelaps()</code>
        /// </summary>
        /// <param name="ObjectOrGroup">The object or group being tested</param>
        /// <param name="InScreenSpace">Whether to take scroll factors into account.</param>
        /// <param name="Camera">Which Camera - currently only one exists</param>
        /// <returns></returns>
        public virtual bool overlaps(FlxBasic ObjectOrGroup, bool InScreenSpace = false, FlxCamera Camera = null)
        {
            if (ObjectOrGroup is FlxGroup)
            {
                bool            results = false;
                int             i       = 0;
                List <FlxBasic> members = new List <FlxBasic>();
                members = (ObjectOrGroup as FlxGroup).members;
                //uint l = (uint)(ObjectOrGroup as FlxGroup).length;
                uint length = (uint)members.Count;
                while (i < length)
                {
                    if (overlaps(members[i++], InScreenSpace, Camera))
                    {
                        results = true;
                    }
                }
                return(results);
            }

            if (ObjectOrGroup is FlxTilemap)
            {
                //Since tilemap's have to be the caller, not the target, to do proper tile-based collisions,
                // we redirect the call to the tilemap overlap here.
                return((ObjectOrGroup as FlxTilemap).overlaps(this, InScreenSpace, Camera));
            }

            FlxObject Object = ObjectOrGroup as FlxObject;

            if (!InScreenSpace)
            {
                return((Object.x + Object.width > x) && (Object.x < x + width) &&
                       (Object.y + Object.height > y) && (Object.y < y + height));
            }

            if (Camera == null)
            {
                Camera = FlxG.camera;
            }
            FlxPoint objectScreenPos = Object.getScreenXY(null, Camera);

            getScreenXY(_point, Camera);
            return((objectScreenPos.x + Object.width > _point.x) && (objectScreenPos.x < _point.x + width) &&
                   (objectScreenPos.y + Object.height > _point.y) && (objectScreenPos.y < _point.y + height));
        }