πŸŒΏπŸ’Ž The humble beginnings of a 2D game engine in Crystal! [in-progress]


Leafgem is the humble beginning of a 2D open source game engine written in Crystal!

Try it out with the demo project!

git clone https://github.com/tfcat/Leafgem.git
cd Leafgem
shards install
crystal run -s -p examples/demo/main.cr

notes to self

flare map files


What are the main things we need for a Game Engine? Here's what I can think of off the top of my head. Each of the given features could be contained in a class which correlates to their purpose.


  • Library / API reference for users
  • Simple text tutorial / demo walkthrough?
  • In-depth class reference for developers?
  • Video tutorials????
  • DEMO GAME (learning Leafgem by example)


  • Keypressing - on_press, on_release and is_pressed
  • Mouse Input - on_click, on_release, and is_pressed for all of the buttons
  • Controller input
  • Touch input


  • Instance-based system. (Unique, contained object instances, derived from a template [class])
  • Destroying objects (self, and foreign)
  • Object selection (e.g. setting attributes of foreign objects )
  • Box collision detection
    • Hit box definition, independent of sprite
  • Per-pixel collision detection


  • Sprite animations + Breaking sprites up into sub-images
  • Text rendering (TTF?)


  • Draw rectangles
  • Draw sprites
  • Draw circles
  • Draw lines
  • Draw polygons


  • Oneshots
  • Looping background music
  • Audio fade in/out over time
  • Multiple sound samples playing at once (the same sample cannot be played on top of itself)


  • Background renderer

    • Parallax scrolling!
  • Foreground renderer

  • Tileset renderer

  • Tile layers

  • Spawn objects in predetermined places

  • Easier workflow regarding room creation... (Currently use Tiled; should I make an editor?)

Known bugs

  • Going above the tilemap results in an invisible duplication of the map, according to the logic in get_tile_at within maps.cr. This results in unexpected true returns with some object functions; meeting_tile and meeting_tile_layer


I'm not all that good with Crystal - I'm creating this project as practice using the Crystal language!

That means any and all contributions to this engine are welcome and heavily appreciated, no matter how big or small. The aim is to give creators an intuitive toolkit for making games quickly and easily!

Any ideas are welcome! Fork, and work your magic!


  • tfcat - creator, developer, maintainer
  • brecert - developer, maintainer
  • rx14 - mentor, sensei, tech support, emotional support
github statistic
  • 73
  • 0
  • 1
  • 4
  • about 1 year ago
  • July 23, 2018

MIT License

Synced at

Fri, 03 Jul 2020 10:37:06 GMT