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

When "entity" is added to "gameword", the "component" of "entity" is initialized once. #1171

Open
lhDream opened this issue Apr 17, 2022 · 0 comments
Labels
type:new feature Adding a feature that isn't currently present

Comments

@lhDream
Copy link
Contributor

lhDream commented Apr 17, 2022

When "Entity" is added to "GameWord", the "Component" of "Entity" is initialized once.
Because some components need to add "Entity" to "GameWord" before they can be fully initialized.
For example:

    @Spawns(PLAYER)
    public Entity newPlayer(SpawnData data) {
        var texture = texture("player.png");
        return entityBuilder(data)
                .type(EntityType.PLAYER)
                .at(getAppWidth() / 2 - texture.getWidth() / 2, getAppHeight() / 2 - texture.getHeight() / 2)
                .viewWithBBox(texture)
                .collidable()
                .with(new TopDownMoveComponent(200).collidables(WALL))
                .build();
    }

This causes "NullPointException", because "colladables" requires "GameWord",but it is obvious that "Entity" has not been added to "GameWord" now.

The following code can solve the problem, but I prefer "component" to complete the whole function, which can reduce the coupling.

entity.setOnActive(()->topDownMoveComponent.collidables(WALL));
@lhDream lhDream added the type:new feature Adding a feature that isn't currently present label Apr 17, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
type:new feature Adding a feature that isn't currently present
Projects
None yet
Development

No branches or pull requests

1 participant