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

FlxSpriteGroup: add insert() #2020

Merged
merged 2 commits into from
Jan 11, 2017
Merged
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
26 changes: 25 additions & 1 deletion flixel/group/FlxSpriteGroup.hx
Original file line number Diff line number Diff line change
Expand Up @@ -246,14 +246,38 @@ class FlxTypedSpriteGroup<T:FlxSprite> extends FlxSprite
* @return The same object that was passed in.
*/
public function add(Sprite:T):T
{
preAdd(Sprite);
return group.add(Sprite);
}

/**
* Inserts a new `FlxSprite` subclass to the group at the specified position.
*
* @param Position The position that the new sprite or sprite group should be inserted at.
* @param Sprite The sprite or sprite group you want to insert into the group.
* @return The same object that was passed in.
*/
public function insert(Position:Int, Sprite:T):T
{
preAdd(Sprite);
return group.insert(Position, Sprite);
}

/**
* Adjusts the position and other properties of the soon-to-be child of this sprite group.
* Private helper to avoid duplicate code in `add()` and `insert()`.
*
* @param Sprite The sprite or sprite group that is about to be added or inserted into the group.
*/
private function preAdd(Sprite:T):Void
{
var sprite:FlxSprite = cast Sprite;
sprite.x += x;
sprite.y += y;
sprite.alpha *= alpha;
sprite.scrollFactor.copyFrom(scrollFactor);
sprite.cameras = _cameras; // _cameras instead of cameras because get_cameras() will not return null
return group.add(Sprite);
}

/**
Expand Down