Gabriel Rebello
Gabriel Rebello

Reputation: 1147

Too many actors in LibGDX?

I'm programming my first game in LibGDX and part of the gameplay has a mixing logic between elements (similar to Doodle God or Little Alchemy). By reading and watching guides, I've attempted to design this logic using LibGDX classes Stage, Actor (for the elements) and Group(for organising elements), but then I realised I would need an actor for each element. Since I intend to have over 150 of them, creating a java class for each one really doesn't feel optimal. Neither do I know an efficient way to store all the logic so I can look for combinations with a single call (I don't want to write a million if statements in a method).

I would like to know if there's a simple and elegant way for doing that. Thanks in advance!

P.S.: The only differences between elements are their textures, the groups they go into and the elements they combine with.

Upvotes: 0

Views: 338

Answers (2)

Shaq
Shaq

Reputation: 377

If you can, reuse Actors maybe?

If we talk about logic. You can group logics and write a function for every group. Don't use ifs, use switch and enums.

Maybe if you tell us more then we can come with something innovative.

Upvotes: 0

Olivier Grégoire
Olivier Grégoire

Reputation: 35467

There is indeed a pattern that is currently well used for doing what you expect. It's called entity-component-system (or ECS).

It requires a shift in thinking how to develop games, but it's worth it, especially for its modularity and reusability.

Wikipedia has a much detailed article about it.

And it's a good thing that libgdx has Ashley, their ECS implementation.

Upvotes: 1

Related Questions