Going to plug my own software here! If you're on linux then I recommend this tool I wrote: https://github.com/leafo/gifine
It lets you easily record a rectangle of a screen, do some basic edits, then convert it into a gif or a mp4 file.
We also have a sticky topic for creating a gif of your game.