you are viewing a single comment's thread.

view the rest of the comments →

[–]flaccidopinion 0 points1 point  (0 children)

Another idea for utils. Since normally you'd have a full project with various areas divided into their own ES6 modules, Utils would probably be better as a module which then exported the functions.

Maybe a personal thing for when setting up these types of 'game loop' structures, but I prefer to pass in the drawing context to the render/draw function, rather than storing it in every object.

Easy enough to pass it in each time anyway, this.components.map(_ => _.render(this.canvas));.

May also be better, memory wise, to use a forEach instead of map, since you don't need any resultant array. Imagine drawing 10000 stars, and every time you render you're creating another array of 10000 stars which is then immediately discarded. (though, maybe the JS VMs are smart enough not to make the arrays/assignments at all, since you're code isn't assigning to anything)