// findPath // simplifyPath // raySimplifyPath // computePathDistance // walkPath override public Boolean overlaps(FlxBasic objectOrGroup, Boolean inScreenSpace = false, FlxCamera camera = null) { if (objectOrGroup is FlxGroup) { Boolean results = false; FlxBasic basic; int i = 0; List <FlxBasic> members = new List <FlxBasic>(); members = (objectOrGroup as FlxGroup).Members; while (i < members.Count) { basic = members[i++] as FlxBasic; if (basic is FlxObject) { if (overlapsWithCallback(basic as FlxObject)) { results = true; } } else { if (overlaps(basic, inScreenSpace, camera)) { results = true; } } } return(results); } else if (objectOrGroup is FlxObject) { return(overlapsWithCallback(objectOrGroup as FlxObject)); } return(false); }
/** * Load objects and/or groups into the quad tree, and register notify and * processing callbacks. * * @param ObjectOrGroup1 Any object that is or extends FlxObject or * FlxGroup. * @param ObjectOrGroup2 Any object that is or extends FlxObject or * FlxGroup. If null, the first parameter will be checked against * itself. * @param NotifyCallback A function with the form * <code>myFunction(Object1:FlxObject,Object2:FlxObject):void</code> * that is called whenever two objects are found to overlap in world * space, and either no ProcessCallback is specified, or the * ProcessCallback returns true. * @param ProcessCallback A function with the form * <code>myFunction(Object1:FlxObject,Object2:FlxObject):Boolean</code> * that is called whenever two objects are found to overlap in world * space. The NotifyCallback is only called if this function returns * true. See FlxObject.separate(). */ public void load(FlxBasic ObjectOrGroup1, FlxBasic ObjectOrGroup2, Func <FlxObject, FlxObject, Boolean> NotifyCallback = null, Func <FlxObject, FlxObject, Boolean> ProcessCallback = null) { add(ObjectOrGroup1, A_LIST); if (ObjectOrGroup2 != null) { add(ObjectOrGroup2, B_LIST); _useBothLists = true; } else { _useBothLists = false; } _notifyCallback = NotifyCallback; _processingCallback = ProcessCallback; }
/** * Call this function to add an object to the root of the tree. This * function will recursively add all group members, but not the groups * themselves. * * @param ObjectOrGroup FlxObjects are just added, FlxGroups are recursed * and their applicable members added accordingly. * @param List A <code>int</code> flag indicating the list to which you want * to add the objects. Options are <code>A_LIST</code> and * <code>B_LIST</code>. */ public void add(FlxBasic ObjectOrGroup, uint List) { _list = List; if (ObjectOrGroup is FlxGroup) { int i = 0; FlxBasic basic; List <FlxBasic> members = ((FlxGroup)ObjectOrGroup).Members; int l = (int)((FlxGroup)(ObjectOrGroup)).length; while (i < l) { basic = members.ElementAt(i++); if ((basic != null) && basic.Exists) { if (basic is FlxGroup) { add(basic, List); } else if (basic is FlxObject) { _object = (FlxObject)basic; if (_object.Exists && _object.AllowCollisions > 0) { _objectLeftEdge = _object.X; _objectTopEdge = _object.Y; _objectRightEdge = _object.X + _object.Width; _objectBottomEdge = _object.Y + _object.Height; addObject(); } } } } } else { _object = (FlxObject)ObjectOrGroup; if (_object.Exists && _object.AllowCollisions > 0) { _objectLeftEdge = _object.X; _objectTopEdge = _object.Y; _objectRightEdge = _object.X + _object.Width; _objectBottomEdge = _object.Y + _object.Height; addObject(); } } }
/** * Load objects and/or groups into the quad tree, and register notify and * processing callbacks. * * @param ObjectOrGroup1 Any object that is or extends FlxObject or * FlxGroup. * @param ObjectOrGroup2 Any object that is or extends FlxObject or * FlxGroup. If null, the first parameter will be checked against * itself. */ public void load(FlxBasic ObjectOrGroup1, FlxBasic ObjectOrGroup2) { load(ObjectOrGroup1, ObjectOrGroup2, null, null); }
/** * Load objects and/or groups into the quad tree, and register notify and * processing callbacks. * * @param ObjectOrGroup1 Any object that is or extends FlxObject or * FlxGroup. * @param ObjectOrGroup2 Any object that is or extends FlxObject or * FlxGroup. If null, the first parameter will be checked against * itself. * @param NotifyCallback A function with the form * <code>myFunction(Object1:FlxObject,Object2:FlxObject):void</code> * that is called whenever two objects are found to overlap in world * space, and either no ProcessCallback is specified, or the * ProcessCallback returns true. */ public void load(FlxBasic ObjectOrGroup1, FlxBasic ObjectOrGroup2, Func <FlxObject, FlxObject, Boolean> NotifyCallback = null) { load(ObjectOrGroup1, ObjectOrGroup2, NotifyCallback, null); }
/// <summary> /// Checks to see if some <code>FlxObject</code> overlaps this <code>FlxObject</code> or <code>FlxGroup</code>. /// If the group has a LOT of things in it, it might be faster to use <code>FlxG.overlaps()</code>. /// WARNING: Currently tilemaps do NOT support screen space overlap checks! /// </summary> /// <param name="objectOrGroup">The object or group being tested.</param> /// <param name="inScreenSpace">Whether to take scroll factors into account when checking for overlap. Default is false, or "only compare in world space."</param> /// <param name="camera">Specify which game camera you want. If null getScreenXY() will just grab the first global camera. flx# - 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; var group = objectOrGroup as FlxGroup; foreach (FlxBasic member in group.Members) { if (overlaps(member, inScreenSpace, camera)) { results = true; // flx# - we could break here, if overlaps does not trigger anything on the remaining members } } /* 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); } var flxObject = objectOrGroup as FlxObject; if(!inScreenSpace) { return (flxObject.X + flxObject.Width > X) && (flxObject.X < X + Width) && (flxObject.Y + flxObject.Height > Y) && (flxObject.Y < Y + Height); } if (camera == null) { camera = FlxG.camera; } FlxPoint objectScreenPos = flxObject.getScreenXY(null, camera); getScreenXY(_tagPoint, camera); return (objectScreenPos.X + flxObject.Width > _tagPoint.X) && (objectScreenPos.X < _tagPoint.X + Width) && (objectScreenPos.Y + flxObject.Height > _tagPoint.Y) && (objectScreenPos.Y < _tagPoint.Y + Height); }
/// <summary> /// Checks to see if this <code>FlxObject</code> were located at the given position, would it overlap the <code>FlxObject</code> or <code>FlxGroup</code>? /// This is distinct from overlapsPoint(), which just checks that point, rather than taking the object's size into account. /// WARNING: Currently tilemaps do NOT support screen space overlap checks! /// </summary> /// <param name="x">The X position you want to check. Pretends this object (the caller, not the parameter) is located here.</param> /// <param name="y">The Y position you want to check. Pretends this object (the caller, not the parameter) is located here.</param> /// <param name="objectOrGroup">The object or group being tested.</param> /// <param name="inScreenSpace">Whether to take scroll factors into account when checking for overlap. Default is false, or "only compare in world space."</param> /// <param name="camera">Specify which game camera you want. If null getScreenXY() will just grab the first global camera. flx# - 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; var group = objectOrGroup as FlxGroup; foreach (FlxBasic member in group.Members) { if (overlapsAt(x, y, member, inScreenSpace, camera)) { results = true; // flx# - we could break here, if overlaps does not trigger anything on the remaining members } } /* 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) { var tilemap = objectOrGroup as FlxTilemap; return tilemap.overlapsAt(tilemap.X - (x - this.X), tilemap.Y - (y - this.Y), this, inScreenSpace, camera); } var flxObject = objectOrGroup as FlxObject; if(!inScreenSpace) { return (flxObject.X + flxObject.Width > x) && (flxObject.X < x + Width) && (flxObject.Y + flxObject.Height > y) && (flxObject.Y < y + Height); } if (camera == null) { camera = FlxG.camera; } FlxPoint objectScreenPos = flxObject.getScreenXY(null, camera); _tagPoint.X = x - camera.Scroll.X * ScrollFactor.X; //copied from getScreenXY() _tagPoint.Y = y - camera.Scroll.Y * ScrollFactor.Y; _tagPoint.X += (_tagPoint.X > 0) ? 0.0000001f : -0.0000001f; _tagPoint.Y += (_tagPoint.Y > 0) ? 0.0000001f : -0.0000001f; return (objectScreenPos.X + flxObject.Width > _tagPoint.X) && (objectScreenPos.X < _tagPoint.X + Width) && (objectScreenPos.Y + flxObject.Height > _tagPoint.Y) && (objectScreenPos.Y < _tagPoint.Y + Height); }
/// <summary> /// Removes an instance of a plugin from the global plugin array. /// </summary> /// <param name="plugin">The plugin instance you want to remove.</param> /// <returns>The same <code>FlxBasic</code>-based plugin you passed in.</returns> public static FlxBasic removePlugin(FlxBasic plugin) { plugins.RemoveAll(existingPlugin => existingPlugin == plugin); return plugin; }
// findPath // simplifyPath // raySimplifyPath // computePathDistance // walkPath public override Boolean overlaps(FlxBasic objectOrGroup, Boolean inScreenSpace = false, FlxCamera camera = null) { if (objectOrGroup is FlxGroup) { Boolean results = false; FlxBasic basic; int i = 0; List<FlxBasic> members = new List<FlxBasic>(); members = (objectOrGroup as FlxGroup).Members; while (i < members.Count) { basic = members[i++] as FlxBasic; if (basic is FlxObject) { if (overlapsWithCallback(basic as FlxObject)) results = true; } else { if (overlaps(basic, inScreenSpace, camera)) results = true; } } return results; } else if (objectOrGroup is FlxObject) { return overlapsWithCallback(objectOrGroup as FlxObject); } return false; }
/// <summary> /// Adds a new plugin to the global plugin array. /// </summary> /// <param name="plugin">Any object that extends FlxBasic. Useful for managers and other things. See org.flixel.plugin for some examples!</param> /// <returns>The same <code>FlxBasic</code>-based plugin you passed in.</returns> public static FlxBasic addPlugin(FlxBasic plugin) { // Don't add repeats if (!plugins.Contains(plugin)) { plugins.Add(plugin); } return plugin; }
/** * Load objects and/or groups into the quad tree, and register notify and * processing callbacks. * * @param ObjectOrGroup1 Any object that is or extends FlxObject or * FlxGroup. * @param ObjectOrGroup2 Any object that is or extends FlxObject or * FlxGroup. If null, the first parameter will be checked against * itself. */ public void load(FlxBasic ObjectOrGroup1, FlxBasic ObjectOrGroup2) { load (ObjectOrGroup1, ObjectOrGroup2, null, null); }
/** * Load objects and/or groups into the quad tree, and register notify and * processing callbacks. * * @param ObjectOrGroup1 Any object that is or extends FlxObject or * FlxGroup. * @param ObjectOrGroup2 Any object that is or extends FlxObject or * FlxGroup. If null, the first parameter will be checked against * itself. * @param NotifyCallback A function with the form * <code>myFunction(Object1:FlxObject,Object2:FlxObject):void</code> * that is called whenever two objects are found to overlap in world * space, and either no ProcessCallback is specified, or the * ProcessCallback returns true. */ public void load(FlxBasic ObjectOrGroup1, FlxBasic ObjectOrGroup2, Func<FlxObject, FlxObject, Boolean> NotifyCallback = null) { load (ObjectOrGroup1, ObjectOrGroup2, NotifyCallback, null); }
/** * Load objects and/or groups into the quad tree, and register notify and * processing callbacks. * * @param ObjectOrGroup1 Any object that is or extends FlxObject or * FlxGroup. * @param ObjectOrGroup2 Any object that is or extends FlxObject or * FlxGroup. If null, the first parameter will be checked against * itself. * @param NotifyCallback A function with the form * <code>myFunction(Object1:FlxObject,Object2:FlxObject):void</code> * that is called whenever two objects are found to overlap in world * space, and either no ProcessCallback is specified, or the * ProcessCallback returns true. * @param ProcessCallback A function with the form * <code>myFunction(Object1:FlxObject,Object2:FlxObject):Boolean</code> * that is called whenever two objects are found to overlap in world * space. The NotifyCallback is only called if this function returns * true. See FlxObject.separate(). */ public void load(FlxBasic ObjectOrGroup1, FlxBasic ObjectOrGroup2, Func<FlxObject, FlxObject, Boolean> NotifyCallback = null, Func<FlxObject, FlxObject, Boolean> ProcessCallback = null) { add (ObjectOrGroup1, A_LIST); if (ObjectOrGroup2 != null) { add (ObjectOrGroup2, B_LIST); _useBothLists = true; } else _useBothLists = false; _notifyCallback = NotifyCallback; _processingCallback = ProcessCallback; }
/** * Call this function to add an object to the root of the tree. This * function will recursively add all group members, but not the groups * themselves. * * @param ObjectOrGroup FlxObjects are just added, FlxGroups are recursed * and their applicable members added accordingly. * @param List A <code>int</code> flag indicating the list to which you want * to add the objects. Options are <code>A_LIST</code> and * <code>B_LIST</code>. */ public void add(FlxBasic ObjectOrGroup, uint List) { _list = List; if (ObjectOrGroup is FlxGroup) { int i = 0; FlxBasic basic; List<FlxBasic> members = ((FlxGroup)ObjectOrGroup).Members; int l = (int)((FlxGroup)(ObjectOrGroup)).length; while (i < l) { basic = members.ElementAt (i++); if ((basic != null) && basic.Exists) { if (basic is FlxGroup) add (basic, List); else if (basic is FlxObject) { _object = (FlxObject)basic; if (_object.Exists && _object.AllowCollisions > 0) { _objectLeftEdge = _object.X; _objectTopEdge = _object.Y; _objectRightEdge = _object.X + _object.Width; _objectBottomEdge = _object.Y + _object.Height; addObject (); } } } } } else { _object = (FlxObject)ObjectOrGroup; if (_object.Exists && _object.AllowCollisions > 0) { _objectLeftEdge = _object.X; _objectTopEdge = _object.Y; _objectRightEdge = _object.X + _object.Width; _objectBottomEdge = _object.Y + _object.Height; addObject (); } } }