HaxeFlixel / flixel

Free, cross-platform 2D game engine powered by Haxe and OpenFL
https://haxeflixel.com/
MIT License
1.97k stars 434 forks source link

Add FlxContainer - a group that removes members from other containers #3050

Closed Geokureli closed 7 months ago

Geokureli commented 7 months ago

A FlxContainer is a FlxGroup that removes it's members from their previous container, when added, meaning a FlxBasic can only ever be in one container at a time. The main benefits is that it ensures a FlxBasic is only in the draw-tree once, where FlxGroups can result in sprites being drawn or updated twice per frame.

The long term goal of this change is to replace FlxSpriteGroup and FlxNestedSprite with a system closer to Flash's DisplayObjectContainer tree, where object's x and y may refer to it's local position in the parent, but the global position may be calculated at any time by iterating up the "parents" until reaching the state. Many flixel features currently can only truly know where a sprite will actually be drawn while in the draw() phase, especially when there are multiple cameras with different zooms.

Related: #2715 By adding a drawContext arg to draw we will be able to pass down vars that dictate how objects are drawn, so in this proposed replacement for FlxSpriteGroup and FlxNestedSprite a parent collection with (for instance) x, y, angle, scale properties will augment the context's transformation matrix with it's properties before passing it to it's members, that will use it to draw their "global" position