HaxeFlixel / HaxeFlixel/flixel

FlxSpriteGroup cloning should keep positions of his children

Open
#1,985 5 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
Haxe
Stars
2.2k
Forks
522
Avg merge
34m
Merged PRs (30d)
1

Description

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

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start by tracing FlxSpriteGroup.clone and the FlxSprite.clone implementation described in the issue. Reproduce the example with two positioned sprites, then verify that the cloned group retains both child positions after group2.setPosition(100, 0).

Written by the indexing model from the issue text.

Assessment

Domain
game-dev
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
45/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.