Book Image

RubyMotion iOS Development Essentials

Book Image

RubyMotion iOS Development Essentials

Overview of this book

RubyMotion is a revolutionary toolchain for iOS app development. With RubyMotion, you can quickly develop and test native iOS apps for the iPhone and iPad, combining the expressiveness and simplicity of Ruby with the power of the iOS SDK. "RubyMotion iOS Development Essentials" is a hands-on guide for developing iOS apps using RubyMotion. With RubyMotion, you can eliminate the complexity and confusion associated with the development of iOS applications using Objective-C. We'll begin from scratch. Starting by installing RubyMotion, we'll build ourselves up to developing an app that uses the various device capabilities iOS has to offer. What's more, we'll even learn how to launch your app on the App Store! We'll also learn to use iOS SDK classes to create application views. Discover how to use the camera, geolocation, gestures, and other device capabilities to create engaging, interactive apps. We'll develop stunning user interfaces faster with the XCode interface builder and make web apps by using WebView. We'll then augment applications with RubyMotion gems, doing more by writing less code and learn how to write test cases for RubyMotion projects. Finally, we'll understand the app submission process to push your app to Apple's App Store With "RubyMotion iOS Development Essentials", we will learn how to create iOS apps with ease. At the end of each chapter we will have a tangible and running app, which utilizes the concepts we have learnt in that chapter.
Table of Contents (19 chapters)
RubyMotion iOS Development Essentials
Credits
About the Authors
Acknowledgement
About the Reviewers
www.PacktPub.com
Preface
Index

Let's create a game – Whac-A-Mole


We will create an iPhone version of the popular arcade game Whac-A-Mole. When the game starts, moles (an animal) will begin to pop up from the bottom of the screen. The objective of the game is to hit the mole, thereby adding to the player's score:

  1. Create an application using the following command:

    motion create GameApp
    
  2. Now, as we are using an external library for our application, let's first install CocoaPods. Run the following commands on your terminal:

    $ sudo gem install cocoapods
    $ pod setup
    $ sudo gem install motion-cocoapods
    
  3. Update the Rakefile:

    $:.unshift("/Library/RubyMotion/lib")
    require 'motion/project'
    require 'motion-cocoapods'
    
    Motion::Project::App.setup do |app|
      # Use 'rake config' to see complete project settings.
      app.name = 'GameApp'
      app.pods do
        pod 'cocos2d'
      end
    end

Now we are all set to begin coding for our app.

Let's start coding!

As in Cocos2D, we need to create a director for starting the game. Let's create one:

  1. Update the app_delegate...