Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Easier extension of FlxTypedTilemap and FlxTile #3154

Merged
merged 1 commit into from
May 29, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions flixel/tile/FlxTile.hx
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package flixel.tile;

import flixel.FlxObject;
import flixel.graphics.frames.FlxFrame;
import flixel.tile.FlxTilemap;
import flixel.util.FlxDirectionFlags;

/**
Expand Down Expand Up @@ -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<FlxTile>;

/**
* The index of this tile type in the core map data.
Expand Down Expand Up @@ -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<FlxTile>, index:Int, width:Float, height:Float, visible:Bool, allowCollisions:FlxDirectionFlags)
{
super(0, 0, width, height);

Expand Down
52 changes: 31 additions & 21 deletions flixel/tile/FlxTilemap.hx
Original file line number Diff line number Diff line change
Expand Up @@ -129,28 +129,10 @@ class FlxTilemap extends FlxTypedTilemap<FlxTile>
{
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<FlxTile>();

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);
}
}

Expand Down Expand Up @@ -384,7 +366,35 @@ class FlxTypedTilemap<Tile:FlxTile> extends FlxBaseTilemap<Tile>

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;
Expand Down
Loading