Skip to content

Commit 8489570

Browse files
authored
Major change to FlxTilemap/FlxTiles Improve collision, debug drawing, add various features (#3158)
* drawDebug boundingBox helpers * allow tile instances to determine overlap * simplify createTile * make overlapsObject dynamic * cc * add orient + forEachOverlappingTile * add separateObjects and similar helpers, revert overlapsWithCallback changes * doc * deprecate overrides * fix deprecation warning * add isOverlappingTile and docs to base * add since * cc * doc * remove new public helpers * extract legacy code to new func * cc * add legacyCollision to coverage * separate tests * cleanup computeOverlap funcs * add separate, computeOverlap tests * check diagonal against walls * check immovable, recursively in collision * add other orient helpers * add overloaded setTile/getTile methods + tests * soft deprecation * small cleanup * better backwards compatibility * add since * more since * more since * dd getRowAt, getColumnAt, rowExists and columnExists * D'oh! * D'OH! * processOverlaps -> objectOverlapsTiles + tests * small changes * test literal edge case * more small stuff * D'OH!!
1 parent 27d0097 commit 8489570

File tree

11 files changed

+1420
-575
lines changed

11 files changed

+1420
-575
lines changed

flixel/FlxObject.hx

Lines changed: 373 additions & 326 deletions
Large diffs are not rendered by default.

flixel/math/FlxRect.hx

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -212,15 +212,18 @@ class FlxRect implements IFlxPooled
212212
}
213213

214214
/**
215-
* Checks to see if some FlxRect object overlaps this FlxRect object.
215+
* Checks to see if this rectangle overlaps another
216216
*
217-
* @param Rect The rectangle being tested.
218-
* @return Whether or not the two rectangles overlap.
217+
* @param rect The other rectangle
218+
* @return Whether the two rectangles overlap
219219
*/
220-
public inline function overlaps(Rect:FlxRect):Bool
220+
public inline function overlaps(rect:FlxRect):Bool
221221
{
222-
var result = (Rect.x + Rect.width > x) && (Rect.x < x + width) && (Rect.y + Rect.height > y) && (Rect.y < y + height);
223-
Rect.putWeak();
222+
final result = rect.right > left
223+
&& rect.left < right
224+
&& rect.bottom > top
225+
&& rect.top < bottom;
226+
rect.putWeak();
224227
return result;
225228
}
226229

flixel/path/FlxPathfinder.hx

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -617,10 +617,8 @@ class FlxTypedPathfinderData<Tilemap:FlxBaseTilemap<FlxObject>>
617617

618618
public function hasValidStartEnd()
619619
{
620-
return startIndex >= 0
621-
&& endIndex >= 0
622-
&& startIndex < map.totalTiles
623-
&& endIndex < map.totalTiles;
620+
return map.tileExists(startIndex)
621+
&& map.tileExists(endIndex);
624622
}
625623

626624
public function destroy()
@@ -647,15 +645,15 @@ class FlxTypedPathfinderData<Tilemap:FlxBaseTilemap<FlxObject>>
647645
*/
648646
inline function getX(tile:Int)
649647
{
650-
return tile % map.widthInTiles;
648+
return map.getColumn(tile);
651649
}
652650

653651
/**
654652
* Helper for converting a tile index to a Y index.
655653
*/
656654
inline function getY(tile:Int)
657655
{
658-
return Std.int(tile / map.widthInTiles);
656+
return map.getRow(tile);
659657
}
660658

661659
/**
@@ -664,7 +662,7 @@ class FlxTypedPathfinderData<Tilemap:FlxBaseTilemap<FlxObject>>
664662
inline function getTileCollisionsByIndex(tile:Int)
665663
{
666664
#if debug numChecks++; #end
667-
return map.getTileCollisions(map.getTileByIndex(tile));
665+
return map.getTileData(tile).allowCollisions;
668666
}
669667
}
670668

0 commit comments

Comments
 (0)