Issue 87 March 4 2010

revMobile for the iPhone: the pre-alpha is here!
Experience the thrill of Rev on the iPhone for the very first time

by Kevin Miller

This is it. The one you've been waiting for. We know you want it and we've got the very first iteration ready for you to try today. Its Rev on the iPhone. No more programming in Objective-C, no struggling with obscure coding and complex interfaces - enjoy the productivity of your favorite authoring environment, Rev, on the most exciting platform around, the iPhone. Rev is going to be the fastest, easiest way to develop iPhone apps.

In this article I'm going to tell you a little more about this exciting addition to the Rev platform, then show you how to create a very simple game on the iPhone that uses multitouch and the shake feature.

What's in the pre-alpha?

Multi-touch - The pre-alpha version includes our first implementation of support for multitouch. That means that you can create interfaces that use gestures. Whether thats pinching objects or moving multiple objects at once, its straightforward with the new touch messages, touchStart, touchMove and touchEnd.

I'll show you how to implement basic movement of multiple objects in a moment.

Accelerometer - You can make your apps respond as your customer moves the phone. It's as simple as using the new accelerationChanged message.

Shake Motion Detection - Implement shake in your applications. Whether you want to implement undo or change the picture, its easy to detect when your iPhone has been shaken. Just intercept the new motionStart, motionEnd and motionRelease messages.

I'll show you how to reset a game using shake in a moment.

Pick Photos from your Photo Library - We've started to implement access to some of the other phone features. In this pre-alpha we include support for picking photos. Use the new iPhonePickPhoto command to pick a photo using the iPhone image chooser.
Picking a photo on the iPhone with Rev using iPhonePickPhoto
 

What's not implemented yet?

This is a pre-alpha, our very first implementation for the iPhone which has many limitations. It is intended to give you a chance to start developing using Rev on the iPhone, to get a feel for what its like and give us feedback to help shape development. Right now a number of things don't work, in particular there is no support for the native iPhone UI theme yet (though you can apply custom skins to your interfaces) and it is not yet possible to submit your apps to the App Store. For more information on the limitations in this pre-alpha take a look here.

Implementing a "Sheep Herder" game

In this article I'm going to talk you through the process of creating a Sheep Herder game for the iPhone. Sheep Herder is a very simple game where you are given 30 seconds to herd as many sheep as possible into the "pen" in the middle of the screen. This game is a good first example because it implements multi-touch, you can move multiple sheep at once and shake detection, to reset the game.

If you want to follow along I recommend you download the completed game stack and open it up in the Rev IDE. You can do that in any desktop Rev product.

Generating Sheep

We start by generating the sheep, a simple process of replicating a sheep button which has its icon set to random locations on the card. For the purposes of this article I'm going to focus on the iPhone specific features of the game, but if you want to see how to replicate the sheep then have a look at the levelGenerate handler in the card script.

Implementing Multitouch

We need to implement the ability to drag sheep into the pen. We're not on the desktop any more and we'd like to use multitouch, to allow the most dexterous of our game players to use multiple fingers to move more than one sheep at once.

Developing an iPhone game, the script editor with multitouch, the iPhone builder and the iPhone simulator - click the image to zoom

Its actually really simple to do this. When the user presses an object, a mouseDown is sent. We set a flag to true so we know that the object is "active":

on mouseDown
   if sGameRunning is true then
      put true into sDragging
   end if
end mouseDown 

Next we use the touchMove message to move the object. touchMove is sent whenever the user's finger holds down on an object. The message comes with 3 parameters, the ID of the object being moved, the x and y coordinates it is being moved to.

on touchMove pId, pX, pY
   if the cType of the target is "sheep" and sDragging is true \
          then
      set the loc of the target to pX, pY
   end if
end touchMove 

Finally, when the user lifts their finger we use touchEnd to detect whether or not the sheep is within the pen, and to stop the dragging process:

on touchEnd pId
   put false into sDragging
   if within(field "pen", the loc of the target) and the cType \
          of the target is "sheep" then
      delete the target
      scoreIncrement
      if the number of controls in group "sheep" < 1 then
         add 1 to sLevel
         levelGenerate
      end if
   end if
end touchEnd 

Shake to Reset

Once the 30 seconds are up, the final score is displayed an the user is instructed to "Shake to reset". To implement this we use the new motionStart message, which is sent with one parameter. (At present the only parameter available is "shake".)

on motionStart pMotion
   if pMotion is "shake" then
      gameStop
      set the layer of group "result" to 1
      hide group "result"
   end if
end motionStart 

Exploring Further

If you want to explore the script of the complete game for your self, the easiest way to do it is to edit the script of the "Start" button then right click on command calls in the script to follow the path of the script.

Tip: Exploring on your own using Go to Definition

A quick note about the graphic performance of this game - at the moment the pre-alpha revMobile engine for the iPhone does not have optimized graphics. The graphics in the pre-alpha are more than adequate to give you smooth game play on this simple game, but if you want to implement more complex graphics then you'll be pleased to know that we will be improving the graphics performance substantially as we get further into the test cycle for revMobile.

You can download the completed game here. You can watch the video of us constructing this game here. You can see our first Lesson about using revMobile here.

Try it yourself today

Join our pre-order program today and help us to shape the future of Rev on the iPhone, as well as saving money and receiving a number of extra benefits. Learn more. But hurry, the program is filling up fast.

 

About the Author

Kevin Miller is CEO for RunRev Ltd.

Main Menu

What's New

Get revMobile Pre-Release