Question: What Game Engine Does Terraria Use?


Terraria, the popular 2D sandbox adventure game developed by Re-Logic, was originally created using Microsoft's XNA framework. However, with the discontinuation of XNA, the developers later migrated to the FNA framework, which is a reimplementation of the XNA framework that is open-source and can be used for cross-platform development.

To further understand the transition, it's important to note that Terraria's gameplay involves exploration, crafting, building, and combat with a variety of creatures in a procedurally generated 2D world. The choice of game engine or framework impacts how these features are implemented and how well they perform on various platforms.

Here is a simplified example to illustrate how one might use FNA to create a basic game structure similar to what could be found in Terraria, highlighting the initialization of the game window and game loop:

using Microsoft.Xna.Framework; using Microsoft.Xna.Framework.Graphics; using Microsoft.Xna.Framework.Input; public class Game1 : Game { GraphicsDeviceManager graphics; SpriteBatch spriteBatch; public Game1() { graphics = new GraphicsDeviceManager(this); Content.RootDirectory = "Content"; // Set your window size or make it full screen graphics.PreferredBackBufferWidth = 800; graphics.PreferredBackBufferHeight = 480; // other initialization code here... } protected override void Initialize() { // TODO: Add your initialization logic here base.Initialize(); } protected override void LoadContent() { spriteBatch = new SpriteBatch(GraphicsDevice); // TODO: use this.Content to load your game content here } protected override void Update(GameTime gameTime) { if (GamePad.GetState(PlayerIndex.One).Buttons.Back == ButtonState.Pressed || Keyboard.GetState().IsKeyDown(Keys.Escape)) Exit(); // TODO: Add your update logic here base.Update(gameTime); } protected override void Draw(GameTime gameTime) { GraphicsDevice.Clear(Color.CornflowerBlue); // TODO: Add your drawing code here base.Draw(gameTime); } }

When starting the game development process, you would expand upon this structure by adding more classes and methods to control game objects, handle physics, manage user input, and render graphics. It's worth noting that while this example is somewhat representative of how a game like Terraria might begin in terms of structure, Terraria itself is a much more complex product with additional considerations for content loading, world generation, multiplayer support, and so forth.

While Terraria is not an open-source game and its actual source code is not publicly available, indie developers often look at frameworks like FNA when developing games with similar ambitions on a technical level.

Was this content helpful?

White Paper

Free System Design on AWS E-Book

Download this early release of O'Reilly's latest cloud infrastructure e-book: System Design on AWS.

Free System Design on AWS E-Book

Start building today

Dragonfly is fully compatible with the Redis ecosystem and requires no code changes to implement.