Player class help

1 - As a class property, definitely. So this.health within your constructor.

2 - Only use a Container if they need to be parented on the display list. If they do, extend Container and use that. Otherwise, just have your class not extend anything, but create Sprite instances as part of its constructor.

3 - If you define them like this, they’ll be global for the class, meaning any instance of the class will all use the same variables, which is almost certainly not what you want. Define them as properties.

See https://exploringjs.com/es6/ch_classes.html for details on classes, private properties, methods, etc.

4 - I wouldn’t have it in a constructor. I would have a method that creates your tween and just call it from your Scene.

5 - Have a method in your Scene called getGameCycle or similar and then call it from your classes, so they all get the correct value from a single source of truth (the Scene).

1 Like