Clone wiki

Core / Codea Programming FAQ

What is Codea?

Codea is made up of several parts. The language you program in is called Lua, which is a small, lightweight scripting language. But don't be fooled - it is very powerful and is used in a number of big name games.

The 3D graphics package used by the iPad, OpenGL ES, has been added on top, along with a physics library, Box2D, which makes it easy to model collisions, gravity, friction, etc.

You shouldn't expect to create GTA in Codea, but you can use it to create a wide variety of projects and games, for fun, for education, and for the app store.

Learning Codea

Codea is the easiest way to learn graphics programming for the iPad, and almost anyone can learn it, but if you haven't programmed before, expect it to be difficult at first, just as if you were learning a foreign language, or to play the piano or learn a new sport.

We recommend you start with Lua, the language behind Codea, and get comfortable with that before you start trying to draw stuff on the screen with Codea.

What projects should I start with?*

The experts recommend you start with well known and fairly simple games like Pacman or Tetris, which will teach you lots of things you need to know. As you get more skilled, you will be able to design your own games.

Measuring speed (frames per second)

Codea doesn't have a built in speed function, but the most common approach is to use DeltaTime, the time since last redraw, since 1/DeltaTime = frames per second. However, this jumps around a lot, so the most common approach is to use a weighted average to smooth it, like this

--in the setup function

--inside the draw function
FPS = FPS * 0.9 + 1/DeltaTime * 0.1

Creating a timer / pausing Codea

If you want something to happen after 2 seconds, the usual approach is to set up a counter, like this

--outside the draw function

--inside the draw function
timer = timer + DeltaTime
if timer > 2 then DoSomething() end

Codea provides a more elegant approach, using tweens like this

--outside the draw function

This will start and stop itself after 2 seconds, then run DoSomething.

If you want something to happen every 2 seconds, then in the first example above, you could reset the counter to 0 every time it reaches 2 seconds. If you use a tween, then you just need to include the tween command again, in the function DoSomething, so there is always a tween running.

Adding more items to the FAQ

  1. you need a basic bitbucket account
  2. then you get the option to edit this page
  3. select Creole (instead of markdown) from the dropdown next to Preview at top right of the text editor
  4. Creole formatting rules are here
  5. to embed code, put three { in front, followed by #!lua on the next line, then the code, then three } at the end

    And before you ask, there seems to be no way to create internal page hyperlinks, so we could just put a list of questions at the top with links to detailed answers below (if you find a way, please explain it here!).