Skip to content

Add FlxGroup#killAll() and FlxGroup#reviveAll() #185

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

Open
wants to merge 2 commits 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
6 changes: 6 additions & 0 deletions src/org/flixel/FlxBasic.as
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,9 @@ package org.flixel
* However, if you want the "corpse" to remain in the game,
* like to animate an effect or whatever, you should override this,
* setting only alive to false, and leaving exists true.
*
* When used in a <code>FlxGroup</code>, the method will kill the group, but leave
* the members alive; use <code>FlxGroup.killAll()</code> to kill any members.
*/
public function kill():void
{
Expand All @@ -136,6 +139,9 @@ package org.flixel
/**
* Handy function for bringing game objects "back to life". Just sets alive and exists back to true.
* In practice, this function is most often called by <code>FlxObject.reset()</code>.
*
* When used in a <code>FlxGroup</code>, the method will revive the group, but leave
* the members as they were; use <code>FlxGroup.reviveAll()</code> to revive any members.
*/
public function revive():void
{
Expand Down
20 changes: 6 additions & 14 deletions src/org/flixel/FlxGroup.as
Original file line number Diff line number Diff line change
Expand Up @@ -555,36 +555,28 @@ package org.flixel
}

/**
* Calls kill on the group's members and then on the group itself.
* Calls <code>kill()<code> on all of the group's members (but not on the group itself).
*/
override public function kill():void
override public function killAll():void
{
var basic:FlxBasic;
var i:uint = 0;
while(i < length)
{
basic = members[i++] as FlxBasic;
var basic:FlxBasic = members[i++] as FlxBasic;
if((basic != null) && basic.exists)
basic.kill();
}

// Kill the group itself
super.kill();
}

/**
* Calls revive on the group itself and then on the group's members.
* Calls <code>revive<code> on all of the group's members (but not on the group itself).
*/
override public function revive():void
public function reviveAll():void
{
// Revive the group itself
super.revive();

var basic:FlxBasic;
var i:uint = 0;
while(i < length)
{
basic = members[i++] as FlxBasic;
var basic:FlxBasic = members[i++] as FlxBasic;
if((basic != null) && !basic.alive)
basic.revive();
}
Expand Down