Skip to content

Conversation

@IQAndreas
Copy link
Member

The FlxGroup will now revive itself, and then all its members.

This is to compliment FlxGroup::kill().

Resolves the following issue:
#30

The FlxGroup will now revive itself, and then all its members.

This is to compliment `FlxGroup::kill()`.
@IQAndreas
Copy link
Member Author

Note that FlxGroup::kill() first kills its children and then itself (a tad macabre).

FlxGroup::revive() goes in the opposite order (first revives itself, then its children). This was mainly in case any children want to double check if their parent (or at least container) is dead or not inside their own revive() functions.

@Dovyski
Copy link
Member

Dovyski commented Sep 21, 2012

Looks good to me. I agree about the order things should happen.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This should be && !basic.exists).

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good catch. Damned my copy-pasting!

But after some thinking, I'm still a bit unclear as to the difference between exists and alive in this context. They seem to be used interchangeably in the code, with the only difference being is draw() is only run if the object exists.

You can read the following in the ASDoc of FlxBasic::kill():

Default behavior is to flag them as nonexistent AND dead. 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.

If the user has done this override on the objects, would it be better to only resurrect the object if it is not alive? Or perhaps check both fields?

if((basic != null) && (!basic.alive || !basic.exists))

Or would the user override the FlxGroup as well to make sure it revives all objects, even ones that are dead but still exist? (this seems unnecessary) Is it easier to always run basic.revive(), and also add a line to FlxBasic::revive() that only revives the object if it is dead? Or maybe if it does not exist? (subclasses would need to make sure they implement this as well)

I think I'm overcomplicating things here. Someone take a step back, look at the class, and let me know what to do. ;)

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I always thought exists and alive are something odd about Flixel. Analyzing FlxGroup::kill(), it checks if the object exists, so I think we should do the same. In that case, all you have to do is add the missing ! to your code.

If we dig too deep, we will end up with all those questions you raised. I think it's enough to test if the object exists before calling revive(). It's something like "if you exist, go back to life; if you are already alive, deal with it yourself" 😄

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would suggest that revive only resurrects objects that are not alive.

if ((basic != null) && !basic.alive)

It's fairly common to override kill to set an objects alive to false but to keep exists true, so that you can leave dead bodies on the screen for example. Having FlxGroup::revive like this would make it easier to revive such objects.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That sounds a good replacement. I never thought about "corpses" in the game :)

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah, yes, I like the alive check.

I made the changes and pushed the commits. Any further changes, or does everything look good now?

It's a minor typo, but with major consequences!

If left unchecked, this bug would revive already existing objects,
leading to several Science Fiction worthy paradoxes.

Also fixed a tiny spelling typo in the ASDoc.
After some discussion on GitHub
https://github.com/FlixelCommunity/flixel/pull/110/files#r1831839
it seems the more logical to check if an object is `alive`,
rather than check if it `exists` when reviving it.
@IQAndreas
Copy link
Member Author

The issues mentioned by @moly in the previous commits have now been fixed.

Does everything look good now?

@Dovyski
Copy link
Member

Dovyski commented Jan 3, 2013

It's good to me.

Dovyski added a commit that referenced this pull request Aug 20, 2013
@Dovyski Dovyski merged commit bdaeb9f into FlixelCommunity:dev Aug 20, 2013
@IQAndreas IQAndreas mentioned this pull request Oct 15, 2013
5 tasks
Dovyski pushed a commit to Dovyski/flixel that referenced this pull request Nov 15, 2013
The following commit has been undone:
FlixelCommunity#110

And a tiny bit of documentation has been added describing the changes.

Discussion:
 - FlixelCommunity#185
 -
FlixelCommunity#30 (comment)
@IQAndreas IQAndreas deleted the fix-flxgroup-kill branch November 17, 2013 22:57
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants