Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improve components with a declarative API #1522

Closed
erickzanardo opened this issue Apr 8, 2022 · 4 comments · Fixed by #1525
Closed

Improve components with a declarative API #1522

erickzanardo opened this issue Apr 8, 2022 · 4 comments · Fixed by #1525

Comments

@erickzanardo
Copy link
Member

What could be improved

Flame already favors composability, Components can have children, their children can have their own and so on.

To put Flame more in line with Flutter APIs, we could a children attribute on all components in order to allow a more declarative way of developing composable components, for example:

add(
  PositionComponent(
    children: [
       SpriteComponent(sprite: playerSprite),
       KeyboardController(),
       ....
    ],
  ),
);

Why should this be improved

It will allow better declarative programming and bring Flame even closer to the "Flutter way"

Any risks?

Idk how complicated this would be to implement, on a naive idea, I think that just by receiving a list o Component on the constructor and adding then all on the component default onLoad will me enough, but we need to test and check if this will bring any issues with the Flame lifecycle.

More information

@erickzanardo
Copy link
Member Author

cc @felangel @alestiago

@spydon
Copy link
Member

spydon commented Apr 8, 2022

Interesting idea! I think it could be pretty nice.

@alestiago
Copy link
Contributor

alestiago commented Apr 8, 2022

I'm in love with this.

Question here is: If children can be specified, what happens when children are also added via the onLoad? How will the children be ordered?

@st-pasha
Copy link
Contributor

st-pasha commented Apr 8, 2022

If children can be specified, what happens when children are also added via the onLoad? How will the children be ordered?

The ones in the constructor come first, those from onLoad after.

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

Successfully merging a pull request may close this issue.

4 participants