Creating A Five Nights At Freddy's Style Game In Defold

Five Nights At Freddy’s is a horror franchise with almost a 10 year history. It popularized the ‘sit and survive’ genre of game and even had a movie come out in October of 2023! A different engine has been traditionally used to make this style of game (and many fan games). I wanted to see if Defold was up for the task of creating something in this style.

I created a YouTube video showing off my process and the journey this game took me on. However, the video is aimed more towards entertainment and comedy. I want to use this forum post to get more into the technical side of things and share my experience.

Video Link:

Game Link:

I started with a template project I created last year. This template includes a basic character controller, settings menu, control rebinding, level loading, main menu, plus some other things. I can use this to quickly prototype and spin up projects.

Since I’m not an artist, and the artist I usually worked with was unavailable, I decided to try Ai art for the bulk of the main game (see more on this in the challenges section).

With the art in hand, I stitched together images and created the main room with a character controller. Creating the camera system ended up being a combination of a gui and loading in a game object. I was able to use the horror-lofi shader (see Libraries used) to get a solid camera feed effect.

In some cases I wasn’t able to find or use my limited knowledge of open-GL to create the effect I wanted. So I just had to create multiple images in some cases. This wouldn’t typically be an issue, but when images are 1152 x 648 each, that results in the project gaining a lot of size.

Rather then including more massive images (one with each combination of monster) I instead kept the monsters in a separate atlas then simply toggled a sprite to display them in the correct rooms. I kept the sprite names, background name, etc consistent between camera feed (each was just a game object) so I was able to reuse a script to display information. I just had to include a with a roomID value to display the correct information.

Programming the monster Ai was a bit of a challenge. I had to create a massive table showing all of the room IDs, what monsters could be in that room, what rooms it connected too, etc. If the game was much larger then this it would have been a major issue to manage. On a timer, the Ai would check if a room could be moved to then would. Since the available space is so small, I just used a random number generator to have the monsters determine what direction to go instead of pathfinding. This works, but occasionally monsters will not appear since the random math is making them run in circles. Beyond that, the Ai mostly was trying to account for corner cases while making the game feel fair. I had issues where monsters would “camp” outside of the player’s space so I had to add a check to force the monster to move after so long.

The audio in the game is a combination of voice acting from my friend and pre-purchased sounds / music. I am happy with how the game feels, the audio certainly enhances the feel. I wasn’t able to find the exact sounds I wanted in some cases.

Testing the game was another huge task. Since I know how the game works under the hood, it became extremely hard to balance. I’m still not entirely sure I have it right. I had to utilize a few friends and continuously tweak it. I’m worried that near the end my friends started to get de-sensitized to the project too. I may have to do a post-release update to make sure the game isn’t too hard or easy.

Libraries Used:

When I first started using Defold in 2018, I rarely used libraries. I tried to program everything myself. It’s still a bad habit I’m trying to break since there are some amazing assets made by the community. Here are a few of my favorites I utilized in this project:

Druid - GitHub - Insality/druid: Powerful Defold UI component framework
About 50% of the games menus use druid, it is an extremely helpful UI library and something I am planning on fully integrating into my template project. The sliders especially where a lifesaver!

Orthographic Camera - GitHub - britzl/defold-orthographic: Orthographic camera functionality for the Defold game engine
I have been using this assets consistently since 2019 but should have been using it since the beginning. This is an extremely useful tool and easily handled everything I needed from a camera. Anything in the render script is usually beyond me so this was extremely useful!

Defos - GitHub - subsoap/defos: Extra native OS functions for games written using the Defold game engine
When I initially created the game, I tried to use the setting “full screen” in the game.project but the mouse wouldn’t display. I used this as a workaround to enable the user to toggle fullscreen using the tab key by default.

Horror Lofi Shader - GitHub - TheKing0x9/horri-fold: A port of Horri-Fi shader to Defold
Used this to create a nice effect for the camera feeds. The static, vignette, CRT curve all resulted in a convincing effect I’m incredibly pleased it. Without this I’m pretty sure the game as a whole wouldn’t work.

Simple Lights -
I used this in combination with the Horror Lofi shader to create a really unique visual design that I utilized for a few minigames. I have a separate forum thread talking about merging the two assets here: [SOLVED] Issue Rending Two Materials Over Each Other.

Ai Art - Ai art has certainly improved a ton since the last time I tried to use it for game development (Using AI Generated Images In Games [Discussion / Devlog]). That being said it still has a number of critical issues such as: lack of style consistency between images, parts of the prompt being ignored, characters looking generic, etc. That being said, some other aspects of the art (such as the melty look and general uncanniness) did play into the game’s favor and added to the feeling of unease.

Animation - All of the jumpscares in the game are just a static image with some screen shake applied as well as some position and scale effects. While I could have used something like spine or dragon bones to provide a little animation. The greater issue was that the Ai art couldn’t generate anything consistently. While programs exist to turn still images into something animated, I’m not sure of how to get video files to play in Defold so opted not to use this.

Holes between sprites - Occasionally in the main office, you can see a seem open between two sprites. I broke the office up into 3 pieces rather then having one massive image. I’ve had this issue occur with tile maps before so I’m not sure what’s causing it.

Voice Acting - First time I seriously tried to implement voice acting in a game! Main issue was remembering to export all of the audio at 44100 hz (my application defaulted to 48000 hz for everything). For Night 1, I had to create a dialog tree system since player action can impact what is said. It took awhile to test but overall I’d say it was worth it.


Overall this project took about 4 months, I initially tried to work on this project with some friends but that mostly fell through. I also got burned out in the middle of the project. Working on it through 3 major Holidays also slowed my progress down substantially. Lastly the YouTube video I made took almost a month. I edit very slowly, about an hour of work results in 15 seconds of video. I am extremely happy with how the game and video turned out!

In conclusion, Defold can absolutely be used to create a Five Nights At Freddy’s style game! I learned a lot from this project and am excited for what comes next.

My friends and I have already been planning our next project, I can’t wait to show you what we’ve been cooking :slight_smile:


Great write-up, thanks for posting. Am I correct in thinking this is a 2D game? No 3D models, perspective camera, that kind of thing.

1 Like

Thanks, glad you enjoyed it!

Correct! The entire game was 2D. The original few Five Nights At Freddy’s games were 2D so it felt right to try doing that. I’d like to try making a 3D game with Defold at some point, just haven’t gotten around to trying it yet

Also, I used a script to count the lines of code and ended up at a total of : 10,569 (includes lines with no code that are just for formatting)

1 Like

Great job. Thanks for sharing.

1 Like