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

Added addAndReturn for easier Component Manipulation #222

Merged
merged 1 commit into from
Jul 1, 2016

Conversation

dlux95
Copy link

@dlux95 dlux95 commented May 24, 2016

Sometimes it is useful to return the Component instead of the Entity. Especially when using the Pooled Engine.

With the PooledEngine you can't use the Constructor of a Component to init its values. The Current API forces you to Keep a reference for every Component when you want to modify data in it when adding a new Entity.

This PR introduces the addAndReturn(Compoment component) Method so you can write something like that:

entity.addAndReturn(pooledEngine.createComponent(ComponentA.class)).set(data1, data2)

Where set() is a method that sets the data of the component. That is much more convenient than

ComponentA componentA = pooledEngine.createComponent(ComponentA.class);
componentA.set(data1, data2);
entity.add(componentA);

Especially when dealing with a lot of components.

I also added a unitTest case for that Method which passes. It also won't break existing API behaviour.

Sometimes it is useful to return the Component instead of the Entity. Especially when using the Pooled Engine
@dlux95
Copy link
Author

dlux95 commented Jun 12, 2016

Some comments on that?

@dsaltares dsaltares merged commit 969dc72 into libgdx:master Jul 1, 2016
@dsaltares
Copy link
Member

Sorry for the delay!

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

Successfully merging this pull request may close these issues.

2 participants