Sparrow.Display.DisplayObject.HitTestPoint C# (CSharp) Méthode

HitTestPoint() public méthode

Returns the object that is found topmost on a point in local coordinates, or null if the test fails.
public HitTestPoint ( Point localPoint ) : DisplayObject
localPoint Point
Résultat DisplayObject
        virtual public DisplayObject HitTestPoint(Point localPoint)
        {
            // TODO its kinda stupid that this functions fails if the object is not touchable
            // invisible or untouchable objects cause the test to fail
            if (!Visible || !Touchable)
            {
                return null;
            }

            // otherwise, check bounding box
            if (BoundsInSpace(this).Contains(localPoint))
            {
                return this; 
            }
            return null;
        }

Usage Example

        override public DisplayObject HitTestPoint(Point localPoint)
        {
            if (!Visible || !Touchable)
            {
                return(null);
            }

            for (int i = _children.Count - 1; i >= 0; --i)
            {
                // front to back!
                DisplayObject child = _children[i];
                Matrix        transformationMatrix = TransformationMatrixToSpace(child);
                Point         transformedPoint     = transformationMatrix.TransformPoint(localPoint);
                DisplayObject target = child.HitTestPoint(transformedPoint);
                if (target != null)
                {
                    return(target);
                }
            }
            return(null);
        }