DownloadsGet the Castle client.Frequently Asked QuestionsLearn more about Castle.ExamplesUse this list of examples to bootstrap your game.Quick StartGet started in under 5 minutes.Creating an AccountWhy and how to create a Castle account.Make Your First GameFollow this small tutorial to get oriented with a basic workflow.Describe your Game with a Castle Project FileThis tutorial will provide an overview and motivation for a project file.Adding Games to your ProfileShare games you made by adding them to your profile on Castle.Hosting Your Own GamesLearn how to add games to Castle which are hosted on another service.Game Dimensions and ScalingChange the dimensions and scaling behavior of your Castle game.Manually Make a New Castle Game from ScratchAn educational resource for advanced usersCastle Project File ReferenceThe project file contains the title, description and other metadata about your game.User API ReferenceGet information about users playing your game.Post API ReferenceIntegrate with Castle's post system.Storage API ReferenceStore shared or per-user data in the cloud.Game API ReferenceNavigate to or get information about other games on Castle.UI API ReferenceDisplay user interface elements such as buttons and text boxes that allow users to interact with your game.System API ReferenceGet information about or perform activities relating to the system Castle is running on.Code Loading API ReferenceLow-level functionality for loading Lua code over the network.Community Reference LinksUseful community links for learning about Lua and LÖVE.

Make Your First Castle Game

By The Castle Team // 1-30-2019
In this short tutorial, we'll get oriented with Castle's basic workflow by creating a new project, drawing a circle, printing some logs, and moving the circle with the arrow keys. You'll need a text editor and a few minutes.

Learning to LÖVE

Castle uses a programming language called Lua, and a framework called LÖVE. If you're already familiar with LÖVE, you're in luck! Anything you can normally do with LÖVE will work in Castle.
If you aren't familiar with LÖVE, we'll go over some of the basics here. You might find the LÖVE API reference page useful to keep open while you work.

Creating a Castle Project

  1. If you don’t have it yet, download and open Castle.
  2. Inside Castle, click the button to create a New Project.
  3. You'll see some different options for starter templates on which to base your new project. For the purpose of this tutorial, choose blank.Creating a new Castle project
  4. When prompted, name your project. You can name it anything you want, but the rest of this tutorial assumes your project is called My Project.
  5. Castle will download some starter files for you. After it's done, go ahead and click the button to Open your new project.

Getting Oriented in Castle

Now that you've opened your new project, Castle should look something like this:
Most of the screen contains your new blank game. Since the blank template doesn't contain much graphics code, it's mostly just a black void right now, with some white text hovering in the middle.
The Logs View on the bottom of the screen is where you'll see development logs while you work.

Editing your Project

Go have a look at the directory where you created your project. Your project directory should contain two files: my-project.castle and main.lua.
Open up main.lua in a text editor of your choice. (Note: See this list if you'd like some recommendations for a text editor.)
The file called my-project.castle doesn't contain any code. Instead, it contains a few lines of configuration which tell Castle how to run your game. For example, you might notice it contains the line main: main.lua. You are welcome to change anything inside my-project.castle, but we won't cover it in depth in this tutorial. Instead, we'll focus solely on main.lua.

Drawing a Circle and Reloading

Let's draw a circle on screen. Inside main.lua, find the two lines that say Delete them and replace them with this:, 0.4, 1.0, 1.0)"fill", 100, 100, 20, 32)
If you'd like to change the circle to be red, try replacing the first line with this:, 0.4, 0.4, 1.0)
Save your file and then click the Reload button in Castle. You can also use Cmd+R (macOS) or Ctrl+R (Windows) to reload.

Printing Logs

If you’d like to debug using logs, Castle has a built-in logger. You can show and hide the Logs View in Castle by pressing Cmd+J (Mac) or Ctrl+J (Windows). If you can't already see the Logs View, try pressing these keys now.
To print a log when the up arrow key is pressed, find the love.update(dt) method at the bottom of main.lua and change it to this:
function love.update(dt)
  if love.keyboard.isDown("up") then
    print("up arrow pressed!")
Save main.lua, then Reload in Castle. Now try pressing the up arrow on your keyboard. You should see some logs appear.

Moving the Circle

Let's move the circle around with the arrow keys.
1. At the very top of main.lua, add this:
local playerPos = {
  x = 100,
  y = 100
2. Find the line with and change it to this:"fill", playerPos.x, playerPos.y, 20, 32)
3. Change the contents of love.update(dt) to this:
if love.keyboard.isDown("right") then 
    playerPos.x = playerPos.x + 256 * dt
  if love.keyboard.isDown("left") then
    playerPos.x = playerPos.x - 256 * dt
  if love.keyboard.isDown("up") then
    playerPos.y = playerPos.y - 256 * dt
  if love.keyboard.isDown("down") then
    playerPos.y = playerPos.y + 256 * dt
Save your revised main.lua, then Reload in Castle. Now try moving the circle around with the arrow keys.

That's it for now!

You should now have a simple program where you can move a circle with the arrow keys. What happens next is up to you!

Next Steps