flixel
flixel copied to clipboard
FlxSpriteGroup cloning should keep positions of his children
- **Flixel 3.3.12 (probably last flixel too because the code behind clone() looks the same)
- OpenFL version: 3.6.1 (probably last openfl too)
- Lime version: 2.9.1 (probably last lime too)
- Affected targets: All I guess
Code snippet reproducing the issue:
package;
import flixel.FlxState;
class PlayState extends FlxState
{
override public function create():Void
{
var group:FlxSpriteGroup = new FlxSpriteGroup();
var p1:FlxSprite= new FlxSprite();
p1.makeGraphic(200, 200, FlxColor.BLUE);
p1.x = 50;
p1.y = 50;
var p2:FlxSprite= new FlxSprite();
p2.makeGraphic(200, 200, FlxColor.RED);
p2.x = 100;
p2.y = 100;
group.add(p1);
group.add(p2);
add(group);
var group2 = group.clone();
group2.setPosition(100, 0);
add(group2);
}
}
Observed behavior: Clone the FlxSprites inside a FlxSpriteGroup but reset their positions to 0. (We don't see the 2 FlxSprites of group2). The clone() method of FlxSprite doesn't include copying the positions, that's probably not a problem for a single FlxSprite but for a group it's annoying. Expected behavior: Clone the FlxSprites inside a FlxSpriteGroup and keep their positions.
So I guess the question is should this behavior exist, and should it be a part of FlxSprite
's clone
or FSG
's clone
.
Exactly.
A "proper" clone method would produce something that's 100% identical, including x, y and everything else I guess. But FlxSprite's clone() really just copies the graphic right now.
@Gama11 so should flixel's clone all properties? And sprite group clones itself and each child recursively?
I'm not sure.