Skip to main content
GameDev.net gamedev.net

PRO Tired of ads? Read GameDev.net ad-free and help keep the community independent with GameDev Pro — $3/month.

Touch and accelerometer functionality available fo

Touch and accelerometer functionality available fo

okonomiyaki
Programmology · · 1 min read
1,759 4
Posted from http://jlongster.com/blog/:

--------------------------------------------

Touch and accelerometer functionality available for Scheme on the iPhone

July 20, 2009



I have finished the Gambit Scheme libraries for touch and accelerometer support. The green smudge was produced by my fingers, and the orange smudge was produced by tilting the phone.

I've introduced a basic events system. To capture a an event, you define an event handler using DEFINE-EVENT-HANDLER. Currently, the only events implemented are "touches-began", "touches-moved", "touches-ended", "touched-cancelled", and "did-accelerate". The arguments of the event are the same as they would be in Objective-C.

Here's an example, taken from the application shown above:
    (define-event-handler (touches-began touches event)      (for-each (lambda (touch)                  (let ((loc (UITouch-location touch)))                    (add-point (car loc) (cdr loc))))                touches))        (define-event-handler (touches-moved touches event)      (for-each (lambda (touch)                  (let ((loc (UITouch-location touch)))                    (add-point (car loc) (cdr loc))))                touches))        (define-event-handler (did-accelerate device accel)      (define (shift n weight)        (+ n (* weight 70)))            (add-point (shift 150 (UIAcceleration-x accel))                 (shift 100 (- (UIAcceleration-y accel)))))

** Download **

I'm still polishing up a few things in these FFIs, but they are ready to use. Soon, I will create a separate github project for Gambit Scheme FFIs. For now, they are included in my gambit scheme on the iphone example project.

Specifically:

lib/ffi/osx.scm
lib/ffi/osx#.scm
lib/ffi/iphone.scm
lib/ffi/iphone#.scm
lib/events.scm

Don't forget to setup a few hooks in your Objective-C app, as seen here (accelerometer) and here (touch).

You can view this iphone application included in my github project as well for example usage.

Discussion

Loading comments...