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

Adding support for multiple tile filters #200

Open
wants to merge 1 commit into
base: dev
Choose a base branch
from
Open
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
21 changes: 17 additions & 4 deletions src/org/flixel/FlxTilemap.as
Original file line number Diff line number Diff line change
Expand Up @@ -943,6 +943,7 @@ package org.flixel
public function overlapsWithCallback(TargetObject:FlxObject,Callback:Function=null,FlipCallbackParams:Boolean=false,Position:FlxPoint=null):Boolean
{
var results:Boolean = false;
var objInFilters:Boolean = false;

var X:Number = x;
var Y:Number = y;
Expand Down Expand Up @@ -1000,7 +1001,19 @@ package org.flixel
}
if(overlapFound)
{
if((tile.callback != null) && ((tile.filter == null) || (TargetObject is tile.filter)))
if (tile.filters != null)
{
for each(var classObj:Class in tile.filters)
{
if (TargetObject is classObj)
{
objInFilters = true;
break;
}
}
}

if((tile.callback != null) && ((tile.filters == null) || (objInFilters)))
{
tile.mapIndex = rowStart+column;
tile.callback(tile,TargetObject);
Expand Down Expand Up @@ -1201,10 +1214,10 @@ package org.flixel
* @param Tile The tile or tiles you want to adjust.
* @param AllowCollisions Modify the tile or tiles to only allow collisions from certain directions, use FlxObject constants NONE, ANY, LEFT, RIGHT, etc. Default is "ANY".
* @param Callback The function to trigger, e.g. <code>lavaCallback(Tile:FlxTile, Object:FlxObject)</code>.
* @param CallbackFilter If you only want the callback to go off for certain classes or objects based on a certain class, set that class here.
* @param CallbackFilters If you only want the callback to go off for certain classes or objects based on a certain class, set those classes here.
* @param Range If you want this callback to work for a bunch of different tiles, input the range here. Default value is 1.
*/
public function setTileProperties(Tile:uint,AllowCollisions:uint=0x1111,Callback:Function=null,CallbackFilter:Class=null,Range:uint=1):void
public function setTileProperties(Tile:uint,AllowCollisions:uint=0x1111,Callback:Function=null,CallbackFilters:Array=null,Range:uint=1):void
{
if(Range <= 0)
Range = 1;
Expand All @@ -1216,7 +1229,7 @@ package org.flixel
tile = _tileObjects[i++] as FlxTile;
tile.allowCollisions = AllowCollisions;
tile.callback = Callback;
tile.filter = CallbackFilter;
tile.filters = CallbackFilters;
}
}

Expand Down
8 changes: 4 additions & 4 deletions src/org/flixel/system/FlxTile.as
Original file line number Diff line number Diff line change
Expand Up @@ -19,12 +19,12 @@ package org.flixel.system
*/
public var callback:Function;
/**
* Each tile can store its own filter class for their callback functions.
* Each tile can store its own filter classes for their callback functions.
* That is, the callback will only be triggered if an object with a class
* type matching the filter touched it.
* type matching any of the filters touched it.
* Defaults to null, set through <code>FlxTilemap.setTileProperties()</code>.
*/
public var filter:Class;
public var filters:Array;
/**
* A reference to the tilemap this tile object belongs to.
*/
Expand Down Expand Up @@ -58,7 +58,7 @@ package org.flixel.system
immovable = true;
moves = false;
callback = null;
filter = null;
filters = null;

tilemap = Tilemap;
index = Index;
Expand Down