DEV Community

CalSch
CalSch

Posted on

How should I structure a game engine/graphics library?

I'm writing a graphics library in TypeScript, but I don't really know how to structure it.

My file structure looks like this:

  • src
    • lib.ts (Imports and exports everything from the other files)
    • game.ts (Manages and renders the game)
    • canvas.ts (Puts the image data from a Game object onto a canvas)
    • math.ts (Math definitions like Vec2, Rect, and dist())
    • util.ts (Useful functions like getting a circles bounding box)
    • sprites.ts (Sprite classes like CircleSpr and RectangleSpr)
  • dst (The compiled JavaScript code with maps)
    • lib.js
    • lib.js.map
    • game.js
    • game.js.map
    • etc.

I feel like I'm doing it wrong because I of things like lib.ts where I just import everything and export it.

If anyone has made a game engine/graphics library, then please let me know how you structured it :)

Top comments (1)

Collapse
 
jakesweb profile image
Jacob Colborn

Right off the cuff the structure seems fine. As you move into more complexity, you will probably want to create directories under src to handle the individual tasks so that you can keep complex file structures together. I know this seems like answering your question with more work, but you can see how phaser.io does it at their github.