Video Game Controllers

A small library of composable controllers that translate touch events into higher level callbacks to control game objects.

The library includes a virtual analogue joystick with central dead-zone, a catapult style interaction for launching projectiles, and tap interpreters that can be used as fire or jump buttons.

Controllers can be composed. A single statement can define a complex control scheme, such as used in a dual-stick shooter, or a shared-screen multiplayer game, or a shared-screen multiplayer dual-stick shooter!

This is a fantastic piece of work. Really well designed.

I want to make something with it now.

Ha! That’s cool - I love getting base common functionality into classes we can drop in. You really need to get something into Examples.lua, or you’re gonna get a ton of questions. I was just working on a space ship pew pew thing, and was just mulling about how to add a control mechanism - you may have done it for me. :slight_smile:

John just tried it out, the analog stick looks really cool.

The example is there now.

Fantastic work, well done and thank you!

I’ve pushed a new version that:

  • Uses named parameters in constructors, making code that uses it much more readable
  • Fires pressed, moved and/or released events from the virtual stick, which makes it easier to write different control schemes (running Vs aiming/shooting)
  • fires pressed and/or released events from the TapAction
  • Has a much simpler example!

I can’t seem to copy from github on my iPad. Does anyone know an easy way? You would think clicking ‘raw’ would do the trick but from that page I can’t select more than 1 word.

It’s possible to copy the raw output, but really tricky. I find if I scroll to the end and select a word, then try to drag one of the handles, it sometimes selects the entire text.

If its your github repo, if you do “edit” on the file, selection works well in the resulting edit window.

If its someone else’s repo, you can either fork it then “edit”, or… Well, I was doing “git clone” to my desktop, to a directory exposed by apache, then browsing locally. Nasty.

I finally jail broke my iPad, and now I git clone, then rsync it over. I will be the first to admit this is all very “beginner hostile”. The sooner we have import/export of some sort, the better - cut and paste is a giant pain.

With an iPad:

  • Go to the raw view of the file
  • Select a word near the top of the file by holding down your finger & picking “select” in the popup menu
  • Drag the left of the selection to the top-left corner of the screen. That will select the entire file.
  • Pick “copy” from the popup menu

Doesn’t always work - or, for me, doesn’t usually work.

Try that at

When you drag the left selection, it… Well, try it on that page.

What you suggest should work, and does for small files - I think it’s line wrap that confuses the curt-and-paste thingamabob. In an “edit” window, it doesn’t wrap lines (it scrolls) and so works. Just a theory.

Yes, curt-and-paste. My iPad is special. Or I am. Or both.

Works for me. But not if the initial selection includes the very start of the file.

I found that copying a text file on Safari Mobile was pretty much hopeless. Once, and only once, I managed to select a line, but other than that I just got words. Opera Mini let me select the whole page (by dragging the anchors) but then the “Copy” box was off the page so I couldn’t actually copy it!

In the end, I downloaded it using an app that allows me to download text files (happened to be GoodReader but I don’t think that’s important). Then I could copy it to the clipboard and paste it into a Codea file.

(If I’m near my home computer then I hook up the iPad and transfer files via libimobiledevice. No jailbreaking required.)

I’ve just pushed a version that adds linear sliders that can have arbitrary orientation. They act like the virtual stick but emit scalar values between -1 &1, not vectors.

Ah, I had some hope with the opera browser but when I pasted it it cut out all the white space including new lines. :confused:

I finally figured out a way to do it in safari. On the raw page, you select the last word of the document, hold the left handle with one finger, flick up to the top with another finger, and finally move your first finger to the first word of the document. It will, hopefully, select the whole document.

By the way, really cool controller Nat!

just picked this up for my pacman game. Pretty cool!

Suggestion on the Controller::activate function. I’d add a callback to the existing touched function to minimize its side effect

temp = touched

touched = function(t)




This is not what it’s designed for.

The activate method is for switching between controllers that need to be active in different modes of the program.

Perhaps the method is misnamed: install or grabFocus might be better terms.