flixel icon indicating copy to clipboard operation
flixel copied to clipboard

FlxSpriteGroup cloning should keep positions of his children

Open loudoweb opened this issue 8 years ago • 5 comments

  • **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.

loudoweb avatar Oct 26 '16 08:10 loudoweb

So I guess the question is should this behavior exist, and should it be a part of FlxSprite's clone or FSG's clone.

MSGhero avatar Oct 26 '16 18:10 MSGhero

Exactly.

loudoweb avatar Oct 26 '16 18:10 loudoweb

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 avatar Oct 26 '16 19:10 Gama11

@Gama11 so should flixel's clone all properties? And sprite group clones itself and each child recursively?

MSGhero avatar Oct 28 '16 19:10 MSGhero

I'm not sure.

Gama11 avatar Oct 28 '16 21:10 Gama11