1
votes

I'm learning libgdx and I've come across a tutorial that made UserData classes for all actors in the game, for example for an actor, player, he made a class PlayerUserData that extended UserData which is an abstract class that had one method called getUserData which returned an enum indicating what kind of actor it was (ground, player, ...). In the tutorial he explained that he made it to store information and that it would be useful for collisions. I don't fully understand this, why wouldn't you store the information in the actor class of the actor? And what information does it have about collisions?

1
This question is too vague to be answered. We don't know what tutorial you're reading or what the author was thinking. You should probably message the tutorial author to ask. Or post a link to it on the Libgdx message board and ask about it there so it can be more of a discussion. - Tenfour04
Okay ill do that - DreamsInHD

1 Answers

1
votes

Sounds complicated... Why not just stick to simple, tried and tested methods such as below;

interface MyActor {

   enum Type {
       // Types of actors
       a, b, c, d
   }
   Type getType();
}

Actor1 implements MyActor
Actor2 implements MyActor
Actor3 implements MyActor
Actor4 implements MyActor

In each Actor that interfaces from MyActor it must return an enum of type MyActor.Type, this way there is no inheritance and actors have no hierarchy where it is clearly not needed.

Each Actor implementing MyActor has its own class, can be stored together in libGDX Collections such as Array<MyActor>() and also be checked for the respective type of the actor without hassle.

EDIT

You could even add the following method to MyActor for easy checking of an actor's type;

boolean isType(Type type);