Game Development Reference
In-Depth Information
Multitouch
Multitouch is supported on the iPad, but it is not handled automatically. You can handle multitouch
by saving the touches into an array and iterating through them between the time that the BEGAN and
ENDED states are triggered. Here's an example:
touches = {}
function touched(touch)
if touch.state == ENDED then
touches[touch.id] = nil
else
touches[touch.id] = touch
end
background(0)
for k,v in pairs(touches) do
math.randomseed(v.id)
fill(math.random(255), math.random(255), math.random(255))
ellipse(v.x, v.y, 100, 100)
end
Caution If you have system-wide multigestures enabled, then you might also want to turn them off
on the iPad from Settings, as they take precedence and interfere with touches if there are more than
two-finger touches.
Making Sound
While other frameworks play WAV or MP3 files, Codea allows for playing dynamically created
waveforms. This has the advantage of taking up less space in the final distribution and also allows
you to create dynamic sounds.
Here's an example of how to create a jump sound:
function touched(touch)
sound(SOUND_JUMP, 1234)
end
Now when you touch the screen, it plays a sound.
Following are the types of predefined built-in sounds in Codea, each one of these have various
settings that can be used as in the example above we use setting #1234:
SOUND_BLIT
SOUND_EXPLODE
SOUND_HIT
 
Search WWH ::




Custom Search