Skip to content

Change draw to take some kind of DrawContext data #2715

Open
@Geokureli

Description

Been thinking on this for a while. We could remove FlxSpriteGroup if the draw() call stack took some kind of matrix or rendering context from their parent group or w/e.

The basic idea

create a DrawContext class with a matrix, and any rendering/color info that you want to bubble down to members. So, calling draw on any container/group will cause it to copy the incoming draw context and augment it with it's own orientation and rendering properties, which it will pass down to it's members. Since FlxGroups do not have orientation or color info, they simply pass down the context they received, verbatim, but FlxNests (Or whatever replaces FlxSpriteGroups) will add their info to the context before passing it down.

Possible fields, these would either be compounded with the parents, or a member might override them if it has a unique or non-null value:

  • matrix/positioning - explained above
  • cameras - just like the current system, a member with null cameras will use the parent's cameras
  • color/shaders/rendering - shaders would likely behave like cameras, where members' shaders override the parent's default, but color can combine, maybe?
  • clipRect - a members' actual clipRect would be the union of both it's own rect and the one passed from the parent

Advantages

Not only will this simplify "nesting" over FlxSpriteGroups, which bubble changes down every time they are changed (creating a ton of caveats and confusion), FlxNexts don't need to be limited to sprite members, you can add basic FlxGroups.

We could also give camera's a DrawContext, or its own orientation and color rendering information, that is applied to all sprites rendered to it, allowing cameras to have rotation (related to #2679)

We could stop setting FlxCamera.defaultCameras in FlxGroup. DrawContext would allow groups to pass their desired cameras down to members.

Drawbacks

The main drawback of this is that you can't perform collision checks between objects in different nests and expect them to collide in regards to their rendered positions, as it will collide them in their respective local positions. This won't effect FlxGroups since their members use the same coordinate space as the group. but the new alternative to FlxSpriteGroups will have this issue

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions