I’m building a game, and for my players I have a player class. This class defines things like their name, xpos, ypos etc. In my main game loop, I have to iterate over all of the current players (it’s multiplayer) and update/draw them.
Problem is, I don’t know how to store the players in the game class. I tried doing this in the game class:
this.players = [];
And then:
game.players.push(new player(name));
But I get this error:
Uncaught TypeError: object is not a function
I always thought I could have objects as array elements, but apparently not.
Could someone advise a better way to do what I want?
Have you defined the player constructor function?
There will need to be code somewhere that follows this format: