Skip to content

Commit

Permalink
FlxGroup: fix splice remove() not decreasing length
Browse files Browse the repository at this point in the history
  • Loading branch information
Gama11 authored and Aurel300 committed Apr 17, 2018
1 parent 50e813a commit eb9356d
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 0 deletions.
3 changes: 3 additions & 0 deletions flixel/group/FlxGroup.hx
Original file line number Diff line number Diff line change
Expand Up @@ -345,7 +345,10 @@ class FlxTypedGroup<T:FlxBasic> extends FlxBasic
return null;

if (Splice)
{
members.splice(index, 1);
length--;
}
else
members[index] = null;

Expand Down
22 changes: 22 additions & 0 deletions tests/unit/src/flixel/group/FlxGroupTest.hx
Original file line number Diff line number Diff line change
Expand Up @@ -152,4 +152,26 @@ class FlxGroupTest extends FlxTest
Assert.areEqual(group.length, group.countLiving());
Assert.areEqual(0, group.countDead());
}

@Test // #2010
function testRemoveSplice()
{
var group = new FlxGroup();
group.add(new FlxBasic());
Assert.areEqual(1, group.length);

group.remove(group.members[0], true);
Assert.areEqual(0, group.length);
}

function testRemoveNoSplice()
{
var group = new FlxGroup();
group.add(new FlxBasic());
Assert.areEqual(1, group.length);

group.remove(group.members[0], false);
Assert.areEqual(1, group.length);
Assert.isNull(group.members[0]);
}
}

0 comments on commit eb9356d

Please sign in to comment.