From 2af1238ae9dc623f83d9443868504f0078a2a7ce Mon Sep 17 00:00:00 2001 From: George Kurelic Date: Tue, 28 May 2024 23:50:35 -0500 Subject: [PATCH] easier extension of FlxTypedTilemap and FlxTile (#3154) --- flixel/tile/FlxTile.hx | 5 ++-- flixel/tile/FlxTilemap.hx | 52 +++++++++++++++++++++++---------------- 2 files changed, 34 insertions(+), 23 deletions(-) diff --git a/flixel/tile/FlxTile.hx b/flixel/tile/FlxTile.hx index a0270ec393..fe7b9c8fe7 100644 --- a/flixel/tile/FlxTile.hx +++ b/flixel/tile/FlxTile.hx @@ -2,6 +2,7 @@ package flixel.tile; import flixel.FlxObject; import flixel.graphics.frames.FlxFrame; +import flixel.tile.FlxTilemap; import flixel.util.FlxDirectionFlags; /** @@ -29,7 +30,7 @@ class FlxTile extends FlxObject /** * A reference to the tilemap this tile object belongs to. */ - public var tilemap:FlxTilemap; + public var tilemap:FlxTypedTilemap; /** * The index of this tile type in the core map data. @@ -60,7 +61,7 @@ class FlxTile extends FlxObject * @param visible Whether the tile is visible or not. * @param allowCollisions The collision flags for the object. By default this value is ANY or NONE depending on the parameters sent to loadMap(). */ - public function new(tilemap:FlxTilemap, index:Int, width:Float, height:Float, visible:Bool, allowCollisions:FlxDirectionFlags) + public function new(tilemap:FlxTypedTilemap, index:Int, width:Float, height:Float, visible:Bool, allowCollisions:FlxDirectionFlags) { super(0, 0, width, height); diff --git a/flixel/tile/FlxTilemap.hx b/flixel/tile/FlxTilemap.hx index ff0aaf16dd..473646d6b8 100644 --- a/flixel/tile/FlxTilemap.hx +++ b/flixel/tile/FlxTilemap.hx @@ -129,28 +129,10 @@ class FlxTilemap extends FlxTypedTilemap { super(); } - - override function initTileObjects():Void + + override function createTile(index, width, height, visible, allowCollisions):FlxTile { - if (frames == null) - return; - - _tileObjects = FlxDestroyUtil.destroyArray(_tileObjects); - // Create some tile objects that we'll use for overlap checks (one for each tile) - _tileObjects = new Array(); - - var length:Int = frames.numFrames; - length += _startingIndex; - - for (i in 0...length) - _tileObjects[i] = new FlxTile(this, i, tileWidth, tileHeight, (i >= _drawIndex), (i >= _collideIndex) ? allowCollisions : NONE); - - // Create debug tiles for rendering bounding boxes on demand - #if FLX_DEBUG - updateDebugTileBoundingBoxSolid(); - updateDebugTileBoundingBoxNotSolid(); - updateDebugTileBoundingBoxPartial(); - #end + return new FlxTile(this, index, width, height, visible, allowCollisions); } } @@ -384,7 +366,35 @@ class FlxTypedTilemap extends FlxBaseTilemap super.destroy(); } + + override function initTileObjects():Void + { + if (frames == null) + return; + + _tileObjects = FlxDestroyUtil.destroyArray(_tileObjects); + // Create some tile objects that we'll use for overlap checks (one for each tile) + _tileObjects = []; + + var length:Int = frames.numFrames; + length += _startingIndex; + + for (i in 0...length) + _tileObjects[i] = createTile(i, tileWidth, tileHeight, (i >= _drawIndex), (i >= _collideIndex) ? allowCollisions : NONE); + // Create debug tiles for rendering bounding boxes on demand + #if FLX_DEBUG + updateDebugTileBoundingBoxSolid(); + updateDebugTileBoundingBoxNotSolid(); + updateDebugTileBoundingBoxPartial(); + #end + } + + function createTile(index, width, height, visible, allowCollisions):Tile + { + throw "createTile not implemented"; + } + function set_frames(value:FlxFramesCollection):FlxFramesCollection { frames = value;