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 aGame
object onto a canvas) -
math.ts
(Math definitions likeVec2
,Rect
, anddist()
) -
util.ts
(Useful functions like getting a circles bounding box) -
sprites.ts
(Sprite classes likeCircleSpr
andRectangleSpr
)
-
-
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)
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.