flappy

RugyKaigi2015 で、RubyMotion に無料版が出たのと、motion-game というゲームライブラリで Flappy Bird が100行で書けてクロスプラットフォームで動く、というのを知りました。
そこで、実際に試してみたら色々とハマったので、その時のメモです。

Rubyで、iOS、Android、OS X、watchOS、tvOS のアプリが作れる RubyMotion は、今まで 199ドル/年するので使ったことはなかったのですが、無料の Starter版が出来ていました。
Starter版は、スプラッシュスクリーンが変えられないこと、iOSの最新安定バージョン向けのみしか動かせないこと、という制限がありますが、ちょっと iOS向けのアプリを Rubyで作ってみるには大変魅力的な製品だと思います。

さらに、cocos2d-x、box2d をベースにした motion-game という 2Dゲームフレームワークもオープンソースとして公開されたことで、同じコードでクロスプラットフォームでゲームが作れるというのも魅力的です。
(RubyMotionでは今後、従来あったJoybox や Apple純正の SpriteKit より、この motion-game を推していくみたいです。)



目次)
0.情報源
1.動作環境
2.インストール
3.動作確認
4.motion-game のインストールと動作確認
4-1)motion-game のインストール
4-2)motion-game の動作確認
5.Flappy Bird を動かす
6.Synbioz vs Zombie を動かす
補足)チュートリアルがうまく動かなかった場合
 


0.情報源 
RubyMotion Starter や motion-game はともに 2015年9月公開で、まだ情報が少なかったので、ここに挙げておきます。

○RubyKaigi2015 での Laurent Sansonetti(@lrz)さんの発表
→・The future of Ruby is in motion! - RubyKaigi 2015




○RubyMotion のチュートリアル
※ 最初に出る「Hello…」画面が、いずれも現在のバージョンのものとは異なります。
→・Getting Started with RubyMotion for iOS and OS X - Manuals - RubyMotion

→・RubyMotion Tutorial: Make iOS Apps With Ruby - rubymotion-tutorial.com
 ・RubyMotion Tutorial: Ruby で iOS アプリを作ろう(日本語訳) - RubyMotion JP

→・RubyMotion JP


○RubyMotion Starter の情報
→・Announcing RubyMotion 4.0: free Starter edition, cross-platform games, watchOS 2.0 - news 2015.9.3 - RubyMotion.com


○motion-game の情報
→・Announcing RubyMotion 4.0: free Starter edition, cross-platform games, watchOS 2.0 - news 2015.9.3 - RubyMotion.com

→・motion-game API reference - developers - RubyMotion.com

→・motion-game - RubyGems.org


※motion-game を使ったサンプルプログラム
→・Samples/ FlappyBird - HipByte/RubyMotionSamples

→・Samples/ Synbioz vs Zombie - introduction_motiongame(仏語) - synbioz - GitHub
 ・(英語)


○RubyMotion による Flappy Bird
※motion-game を使ったもの
→・RubyMotionSamples/game/FlappyBird - HipByte - GitHub


※以下は、SpriteKit を使ったものなので、今回は使わない
(RubyMotionSamples には、違うフォルダに 2種類の Flappy Bird が収録されているので注意)
→・SKFun/ SpriteKit and RubyMotion - Will Raxworthy
 (RubyMotionSamples/ios/FlappyBird - HipByte - GitHub/  RubyMotion.com
 (flappin-motion - willrax - GitHub

→・FlappyMotion - torben - GitHub



1.動作環境
・OS X 10.11.2 El Capitan
・Xcode 7.2
・Ruby 2.2.3
・RubyMotion 4.7
・motion-game 1.1
 (RubyMotion には Mac が必要です)



2.インストール
RubyMotion のインストールは、下記記事の通りにしてください。
→・RubyMotion:導入編 - akatsuki174 - Qiita 

RubyMotion_download
                                                      <img via rubymotion.com>



3.動作確認
チュートリアルで動作確認するには、下記記事が参考になりました。
→・RubyMotionに入門してみる - totz - Qiita

(以下、赤文字が入力)
※ バージョンの確認
$ motion --version
4.7

※ 4.7 以下の場合は、RubyMotion をバージョンアップします。
$ sudo motion update

※ ヘルプ
$ motion --help
RubyMotion lets you develop native iOS, OS X and Android applications using the awesome Ruby language.

Commands:

    * account          Access account details.
    * activate         Activate software license.
    * android-setup    Setup the Android environment.
    * changelog        View the changelog.
    * create           Create a new project.
    * device-console   Print iOS device logs
    * ri               Display API reference.
    * support          Create a support ticket.
    * update           Update the software.

Options:

    --version   Show the version of RubyMotion
    --no-ansi   Show output without ANSI codes
    --verbose   Show more debugging information
    --help      Show help banner of specified command


ここから、チュートリアルの通りにしていきます。
$ motion create HelloMotion
    Create HelloMotion
    Create HelloMotion/.gitignore
    Create HelloMotion/app/app_delegate.rb
    Create HelloMotion/Gemfile
    Create HelloMotion/Rakefile
    Create HelloMotion/resources/Default-568h@2x.png
    Create HelloMotion/resources/Default-667h@2x.png
    Create HelloMotion/resources/Default-736h@3x.png
    Create HelloMotion/spec/main_spec.rb
 
$ cd HelloMotion
$ rake
     Build ./build/iPhoneSimulator-9.2-Development
   Compile ./app/app_delegate.rb
    Create ./build/iPhoneSimulator-9.2-Development/HelloMotion.app
      Link ./build/iPhoneSimulator-9.2-Development/HelloMotion.app/HelloMotion
    Create ./build/iPhoneSimulator-9.2-Development/HelloMotion.app/PkgInfo
    Create ./build/iPhoneSimulator-9.2-Development/HelloMotion.app/Info.plist
      Copy ./resources/Default-568h@2x.png
      Copy ./resources/Default-667h@2x.png
      Copy ./resources/Default-736h@3x.png
      Copy /Library/RubyMotion/lib/motion/project/template/ios/launch_image/launch_screen.png
      Copy /Library/RubyMotion/lib/motion/project/template/ios/launch_image/launch_screen.storyboardc
    Create ./build/iPhoneSimulator-9.2-Development/HelloMotion.app.dSYM
      Copy ./build/iPhoneSimulator-9.2-Development/HelloMotion.app.dSYM
  Simulate ./build/iPhoneSimulator-9.2-Development/HelloMotion.app
*** Starting simulator
ここで、iOS Simulator が起動します。

RubyMotion_splash
まず、Starter版のスプラッシュスクリーンが表示されます。

RubyMotion_Hello1a
続いて、何もないウィンドウかと思ったら…

RubyMotion_Hello2a

スクロールしたら、ウィンドウの上部にタイトルが表示されていました。
これで OKです。
(上で挙げた各種チュートリアルに載っているウィンドウ表示の情報は古くなっています。)


終了するには、exit
 (main)> exit 
RubyMotion_Hello3
iOS Simulator のホーム画面が表示されます。


※ iOS Simulator をリセットするには;
Simulator>Reset Content and Settings…>Resetボタンを押す 


※ チュートリアルがうまく動かなかった場合は、後述の 補足)を参照のこと。



4.motion-game のインストールと動作確認
4-1)motion-game のインストール

$ gem install motion-game

※ gem の確認方法
$ gem list
 
*** LOCAL GEMS ***
(略)
motion-game (1.1)
 

4-2)motion-game の動作確認
下記記事の「Hello World」で動作確認します。
→・An introduction to smartphone game development with motion-game - news 2015.12.6 - RubyMotion.com


$ motion create --template=motion-game hello
    Create hello
    Create hello/app/application.rb
    Create hello/app/main_scene.rb
    Create hello/config/android.rb
    Create hello/config/ios.rb
    Create hello/Gemfile
    Create hello/Rakefile
$ cd hello
$ rake ios:simulator
     Build build/ios/iPhoneSimulator-9.2-Development
     Build /Users/xxx/.rbenv/versions/2.2.3/lib/ruby/gems/2.2.0/gems/motion-game-1.1/lib/motion-game/../../build/ios
   Compile ./app/main_scene.rb
   Compile ./app/application.rb
   Compile /Users/xxx/.rbenv/versions/2.2.3/lib/ruby/gems/2.2.0/gems/motion-game-1.1/lib/motion-game/ios/root_view_controller.rb
   Compile /Users/xxx/.rbenv/versions/2.2.3/lib/ruby/gems/2.2.0/gems/motion-game-1.1/lib/motion-game/ios/app_delegate.rb
    Create build/ios/iPhoneSimulator-9.2-Development/hello.app
      Link build/ios/iPhoneSimulator-9.2-Development/hello.app/hello
    Create build/ios/iPhoneSimulator-9.2-Development/hello.app/PkgInfo
    Create build/ios/iPhoneSimulator-9.2-Development/hello.app/Info.plist
      Copy /Library/RubyMotion/lib/motion/project/template/ios/launch_image/launch_screen.png
      Copy /Library/RubyMotion/lib/motion/project/template/ios/launch_image/launch_screen.storyboardc
    Create build/ios/iPhoneSimulator-9.2-Development/hello.app.dSYM
      Copy build/ios/iPhoneSimulator-9.2-Development/hello.app.dSYM
  Simulate build/ios/iPhoneSimulator-9.2-Development/hello.app
*** Starting simulator
ここで、iOS Simulator が起動します。スプラッシュスクリーンが表示された後;

motion-game1
このウィンドウが表示されれば OKです。


ただし、エラー表示が出ます。(問題無い?) 
(main)> 2016-01-02 11:51:31.514 hello[2632:241397] Error loading /System/Library/Extensions/IOHIDFamily.kext/Contents/PlugIns/IOHIDLib.plugin/Contents/MacOS/IOHIDLib:  dlopen(/System/Library/Extensions/IOHIDFamily.kext/Contents/PlugIns/IOHIDLib.plugin/Contents/MacOS/IOHIDLib, 262): no suitable image found.  Did find:
/System/Library/Extensions/IOHIDFamily.kext/Contents/PlugIns/IOHIDLib.plugin/Contents/MacOS/IOHIDLib: mach-o, but not built for iOS simulator
2016-01-02 11:51:31.514 hello[2632:241397] Cannot find function pointer IOHIDLibFactory for factory 13AA9C44-6F1B-11D4-907C-0005028F18D5 in CFBundle/CFPlugIn 0x10f2cc3b0 </System/Library/Extensions/IOHIDFamily.kext/Contents/PlugIns/IOHIDLib.plugin> (bundle, not loaded)
2016-01-02 11:51:31.515 hello[2632:241397] Error loading /System/Library/Extensions/IOHIDFamily.kext/Contents/PlugIns/IOHIDLib.plugin/Contents/MacOS/IOHIDLib:  dlopen(/System/Library/Extensions/IOHIDFamily.kext/Contents/PlugIns/IOHIDLib.plugin/Contents/MacOS/IOHIDLib, 262): no suitable image found.  Did find:
/System/Library/Extensions/IOHIDFamily.kext/Contents/PlugIns/IOHIDLib.plugin/Contents/MacOS/IOHIDLib: mach-o, but not built for iOS simulator
2016-01-02 11:51:31.515 hello[2632:241397] Cannot find function pointer IOHIDLibFactory for factory 13AA9C44-6F1B-11D4-907C-0005028F18D5 in CFBundle/CFPlugIn 0x10f2cc3b0 </System/Library/Extensions/IOHIDFamily.kext/Contents/PlugIns/IOHIDLib.plugin> (bundle, not loaded)
2016-01-02 11:51:31.516 hello[2632:241397] Error loading /System/Library/Extensions/IOHIDFamily.kext/Contents/PlugIns/IOHIDLib.plugin/Contents/MacOS/IOHIDLib:  dlopen(/System/Library/Extensions/IOHIDFamily.kext/Contents/PlugIns/IOHIDLib.plugin/Contents/MacOS/IOHIDLib, 262): no suitable image found.  Did find:
/System/Library/Extensions/IOHIDFamily.kext/Contents/PlugIns/IOHIDLib.plugin/Contents/MacOS/IOHIDLib: mach-o, but not built for iOS simulator
2016-01-02 11:51:31.516 hello[2632:241397] Cannot find function pointer IOHIDLibFactory for factory 13AA9C44-6F1B-11D4-907C-0005028F18D5 in CFBundle/CFPlugIn 0x10f2cc3b0 </System/Library/Extensions/IOHIDFamily.kext/Contents/PlugIns/IOHIDLib.plugin> (bundle, not loaded)
2016-01-02 11:51:31.517 hello[2632:241397] Error loading /System/Library/Extensions/IOHIDFamily.kext/Contents/PlugIns/IOHIDLib.plugin/Contents/MacOS/IOHIDLib:  dlopen(/System/Library/Extensions/IOHIDFamily.kext/Contents/PlugIns/IOHIDLib.plugin/Contents/MacOS/IOHIDLib, 262): no suitable image found.  Did find:
/System/Library/Extensions/IOHIDFamily.kext/Contents/PlugIns/IOHIDLib.plugin/Contents/MacOS/IOHIDLib: mach-o, but not built for iOS simulator
2016-01-02 11:51:31.517 hello[2632:241397] Cannot find function pointer IOHIDLibFactory for factory 13AA9C44-6F1B-11D4-907C-0005028F18D5 in CFBundle/CFPlugIn 0x10f2cc3b0 </System/Library/Extensions/IOHIDFamily.kext/Contents/PlugIns/IOHIDLib.plugin> (bundle, not loaded)
2016-01-02 11:51:31.517 hello[2632:241397] Error loading /System/Library/Extensions/IOHIDFamily.kext/Contents/PlugIns/IOHIDLib.plugin/Contents/MacOS/IOHIDLib:  dlopen(/System/Library/Extensions/IOHIDFamily.kext/Contents/PlugIns/IOHIDLib.plugin/Contents/MacOS/IOHIDLib, 262): no suitable image found.  Did find:
/System/Library/Extensions/IOHIDFamily.kext/Contents/PlugIns/IOHIDLib.plugin/Contents/MacOS/IOHIDLib: mach-o, but not built for iOS simulator
2016-01-02 11:51:31.518 hello[2632:241397] Cannot find function pointer IOHIDLibFactory for factory 13AA9C44-6F1B-11D4-907C-0005028F18D5 in CFBundle/CFPlugIn 0x10f2cc3b0 </System/Library/Extensions/IOHIDFamily.kext/Contents/PlugIns/IOHIDLib.plugin> (bundle, not loaded)



5.Flappy Bird を動かす
motion-game版 Flappy Bird をダウンロードします。
RubyMotionSamples - HipByte - GitHub をダウンロードして、解凍した RubyMotionSamples-master/game/FlappyBird がコードです。

$ cd RubyMotionSamples-master/game/FlappyBird
$ rake ios:simulator
rake aborted!
Bundler::GemNotFound: Could not find motion-game-1.0 in any of the sources
/Users/xxx/Desktop/RubyMotionSamples-master/game/FlappyBird/Rakefile:5:in `<top (required)>'
(See full trace by running task with --trace)
motion-game-1.0 でないといけないようです。

$ gem uninstall motion-game
Successfully uninstalled motion-game-1.1
$ gem install motion-game -v 1.0
Fetching: motion-game-1.0.gem (100%)
Successfully installed motion-game-1.0
Parsing documentation for motion-game-1.0
Installing ri documentation for motion-game-1.0
Done installing documentation for motion-game after 0 seconds
1 gem installed

再度 rake
$ rake ios:simulator
     Build build/ios/iPhoneSimulator-9.2-Development
     Build /Users/xxx/.rbenv/versions/2.2.3/lib/ruby/gems/2.2.0/gems/motion-game-1.0/lib/motion-game/../../build/ios
   Compile ./app/application.rb
   Compile /Users/xxx/.rbenv/versions/2.2.3/lib/ruby/gems/2.2.0/gems/motion-game-1.0/lib/motion-game/ios/root_view_controller.rb
   Compile ./app/main_scene.rb
   Compile /Users/xxx/.rbenv/versions/2.2.3/lib/ruby/gems/2.2.0/gems/motion-game-1.0/lib/motion-game/ios/app_delegate.rb
    Create build/ios/iPhoneSimulator-9.2-Development/FlappyBird.app
      Link build/ios/iPhoneSimulator-9.2-Development/FlappyBird.app/FlappyBird
    Create build/ios/iPhoneSimulator-9.2-Development/FlappyBird.app/PkgInfo
    Create build/ios/iPhoneSimulator-9.2-Development/FlappyBird.app/Info.plist
      Copy ./resources/bird_one.png
      Copy ./resources/bird_three.png
      Copy ./resources/bird_two.png
      Copy ./resources/Default-568h@2x.png
      Copy ./resources/ground.png
      Copy ./resources/pipe_down.png
      Copy ./resources/pipe_up.png
      Copy ./resources/sfx_hit.caf
      Copy ./resources/sfx_hit.wav
      Copy ./resources/sfx_point.caf
      Copy ./resources/sfx_point.wav
      Copy ./resources/sfx_wing.caf
      Copy ./resources/sfx_wing.wav
      Copy ./resources/skyline.png
      Copy /Library/RubyMotion/lib/motion/project/template/ios/launch_image/launch_screen.png
      Copy /Library/RubyMotion/lib/motion/project/template/ios/launch_image/launch_screen.storyboardc
    Create build/ios/iPhoneSimulator-9.2-Development/FlappyBird.app.dSYM
while processing /Users/xxx/.rbenv/versions/2.2.3/lib/ruby/gems/2.2.0/gems/motion-game-1.0/build/ios/libtiff.a(tif_dirread.o):
warning: no mapping for range.
while processing /Users/xxx/.rbenv/versions/2.2.3/lib/ruby/gems/2.2.0/gems/motion-game-1.0/build/ios/libtiff.a(tif_flush.o):
warning: no mapping for range.
      Copy build/ios/iPhoneSimulator-9.2-Development/FlappyBird.app.dSYM
  Simulate build/ios/iPhoneSimulator-9.2-Development/FlappyBird.app
*** Starting simulator
ここで、iOS Simulator が起動します。スプラッシュスクリーンが表示された後;

flappy
Flappy Bird が始まります!クリックで上昇します。


実行中、先ほどと同じようなエラーが出ます。
(main)> libpng warning: iCCP: known incorrect sRGB profile
Initializing cpSpace - Chipmunk v6.2.1 (Debug Enabled)
Compile with -DNDEBUG defined to disable debug mode and runtime assertion checks
2016-01-02 12:47:18.099 FlappyBird[37265:3523596] Error loading /System/Library/Extensions/IOHIDFamily.kext/Contents/PlugIns/IOHIDLib.plugin/Contents/MacOS/IOHIDLib:  dlopen(/System/Library/Extensions/IOHIDFamily.kext/Contents/PlugIns/IOHIDLib.plugin/Contents/MacOS/IOHIDLib, 262): no suitable image found.  Did find:
/System/Library/Extensions/IOHIDFamily.kext/Contents/PlugIns/IOHIDLib.plugin/Contents/MacOS/IOHIDLib: mach-o, but not built for iOS simulator
2016-01-02 12:47:18.100 FlappyBird[37265:3523596] Cannot find function pointer IOHIDLibFactory for factory 13AA9C44-6F1B-11D4-907C-0005028F18D5 in CFBundle/CFPlugIn 0x112221b30 </System/Library/Extensions/IOHIDFamily.kext/Contents/PlugIns/IOHIDLib.plugin> (bundle, not loaded)
2016-01-02 12:47:18.101 FlappyBird[37265:3523596] Error loading /System/Library/Extensions/IOHIDFamily.kext/Contents/PlugIns/IOHIDLib.plugin/Contents/MacOS/IOHIDLib:  dlopen(/System/Library/Extensions/IOHIDFamily.kext/Contents/PlugIns/IOHIDLib.plugin/Contents/MacOS/IOHIDLib, 262): no suitable image found.  Did find:
/System/Library/Extensions/IOHIDFamily.kext/Contents/PlugIns/IOHIDLib.plugin/Contents/MacOS/IOHIDLib: mach-o, but not built for iOS simulator
2016-01-02 12:47:18.101 FlappyBird[37265:3523596] Cannot find function pointer IOHIDLibFactory for factory 13AA9C44-6F1B-11D4-907C-0005028F18D5 in CFBundle/CFPlugIn 0x112221b30 </System/Library/Extensions/IOHIDFamily.kext/Contents/PlugIns/IOHIDLib.plugin> (bundle, not loaded)
2016-01-02 12:47:18.101 FlappyBird[37265:3523596] Error loading /System/Library/Extensions/IOHIDFamily.kext/Contents/PlugIns/IOHIDLib.plugin/Contents/MacOS/IOHIDLib:  dlopen(/System/Library/Extensions/IOHIDFamily.kext/Contents/PlugIns/IOHIDLib.plugin/Contents/MacOS/IOHIDLib, 262): no suitable image found.  Did find:
/System/Library/Extensions/IOHIDFamily.kext/Contents/PlugIns/IOHIDLib.plugin/Contents/MacOS/IOHIDLib: mach-o, but not built for iOS simulator
2016-01-02 12:47:18.102 FlappyBird[37265:3523596] Cannot find function pointer IOHIDLibFactory for factory 13AA9C44-6F1B-11D4-907C-0005028F18D5 in CFBundle/CFPlugIn 0x112221b30 </System/Library/Extensions/IOHIDFamily.kext/Contents/PlugIns/IOHIDLib.plugin> (bundle, not loaded)
2016-01-02 12:47:18.102 FlappyBird[37265:3523596] Error loading /System/Library/Extensions/IOHIDFamily.kext/Contents/PlugIns/IOHIDLib.plugin/Contents/MacOS/IOHIDLib:  dlopen(/System/Library/Extensions/IOHIDFamily.kext/Contents/PlugIns/IOHIDLib.plugin/Contents/MacOS/IOHIDLib, 262): no suitable image found.  Did find:
/System/Library/Extensions/IOHIDFamily.kext/Contents/PlugIns/IOHIDLib.plugin/Contents/MacOS/IOHIDLib: mach-o, but not built for iOS simulator
2016-01-02 12:47:18.102 FlappyBird[37265:3523596] Cannot find function pointer IOHIDLibFactory for factory 13AA9C44-6F1B-11D4-907C-0005028F18D5 in CFBundle/CFPlugIn 0x112221b30 </System/Library/Extensions/IOHIDFamily.kext/Contents/PlugIns/IOHIDLib.plugin> (bundle, not loaded)
2016-01-02 12:47:18.103 FlappyBird[37265:3523596] Error loading /System/Library/Extensions/IOHIDFamily.kext/Contents/PlugIns/IOHIDLib.plugin/Contents/MacOS/IOHIDLib:  dlopen(/System/Library/Extensions/IOHIDFamily.kext/Contents/PlugIns/IOHIDLib.plugin/Contents/MacOS/IOHIDLib, 262): no suitable image found.  Did find:
/System/Library/Extensions/IOHIDFamily.kext/Contents/PlugIns/IOHIDLib.plugin/Contents/MacOS/IOHIDLib: mach-o, but not built for iOS simulator
2016-01-02 12:47:18.103 FlappyBird[37265:3523596] Cannot find function pointer IOHIDLibFactory for factory 13AA9C44-6F1B-11D4-907C-0005028F18D5 in CFBundle/CFPlugIn 0x112221b30 </System/Library/Extensions/IOHIDFamily.kext/Contents/PlugIns/IOHIDLib.plugin> (bundle, not loaded)
game over!
exit

なお、
$ rake ios:simulator
Could not find rake-10.4.2 in any of the sources
Run `bundle install` to install missing gems.
というエラーも途中で出ましたが(rake-10.4.2 はインストール済みにも関わらず)、
再度インストールして上書きすることで、エラーが出なくなりました。

$ gem install rake
Fetching: rake-10.4.2.gem (100%)
rake's executable "rake" conflicts with /Users/xxx/.rbenv/versions/2.2.3/bin/rake
Overwrite the executable? [yN]  y
Successfully installed rake-10.4.2
Parsing documentation for rake-10.4.2
Installing ri documentation for rake-10.4.2
Done installing documentation for rake after 1 seconds
1 gem installed



6.Synbioz vs Zombie を動かす
motion-game のもう一つのサンプルゲームも動かしてみます。
下記記事の「Synbioz vs Zombie」です。

Samples/ Synbioz vs Zombie - introduction_motiongame(仏語) - synbioz - GitHub
のコードをダウンロードして解凍します。

$ cd introduction_motiongame-master 
$ rake ios:simulator
     Build build/ios/iPhoneSimulator-9.2-Development
     Build /Users/xxx/.rbenv/versions/2.2.3/lib/ruby/gems/2.2.0/gems/motion-game-1.1/lib/motion-game/../../build/ios
   Compile ./app/scenes.rb
   Compile ./app/scenes/survivor_scene.rb
   Compile ./app/scenes/main_scene.rb
   Compile ./app/scenes/game_over_scene.rb
   Compile ./app/application.rb
   Compile /Users/xxx/.rbenv/versions/2.2.3/lib/ruby/gems/2.2.0/gems/motion-game-1.1/lib/motion-game/ios/root_view_controller.rb
   Compile /Users/xxx/.rbenv/versions/2.2.3/lib/ruby/gems/2.2.0/gems/motion-game-1.1/lib/motion-game/ios/app_delegate.rb
    Create build/ios/iPhoneSimulator-9.2-Development/intro_mg.app
      Link build/ios/iPhoneSimulator-9.2-Development/intro_mg.app/intro_mg
    Create build/ios/iPhoneSimulator-9.2-Development/intro_mg.app/PkgInfo
    Create build/ios/iPhoneSimulator-9.2-Development/intro_mg.app/Info.plist
      Copy ./resources/night.wav
      Copy ./resources/survivors
      Copy ./resources/zombie.png
      Copy /Library/RubyMotion/lib/motion/project/template/ios/launch_image/launch_screen.png
      Copy /Library/RubyMotion/lib/motion/project/template/ios/launch_image/launch_screen.storyboardc
    Create build/ios/iPhoneSimulator-9.2-Development/intro_mg.app.dSYM
      Copy build/ios/iPhoneSimulator-9.2-Development/intro_mg.app.dSYM
  Simulate build/ios/iPhoneSimulator-9.2-Development/intro_mg.app
*** Starting simulator
iOS Simulator が起動して、スプラッシュスクリーンの後;

motion-game_zombie1
この画面で、人物名をクリックしても次の画面に移行しません。


$ gem list

*** LOCAL GEMS ***
(略)
motion-game (1.1)

そこで、motion-game を 1.0 にしてみます。
$ gem uninstall motion-game
Successfully uninstalled motion-game-1.1
$ gem install motion-game -v 1.0
Fetching: motion-game-1.0.gem (100%)
Successfully installed motion-game-1.0
Parsing documentation for motion-game-1.0
Installing ri documentation for motion-game-1.0
Done installing documentation for motion-game after 0 seconds
1 gem installed

再度、rake
$ rake ios:simulator
rake aborted!
Bundler::GemNotFound: Could not find motion-game-1.1 in any of the sources
/Users/xxx/introduction_motiongame-master/Rakefile:5:in `<top (required)>'
(See full trace by running task with --trace)

前回の設定が Gemfile.lock に motion-game-1.1 を使うよう残ってしまっているので、
もう一度サンプルファイルを解凍し直すか、Gemfile.lock を削除して、再び rake。
$ rake ios:simulator
     Build build/ios/iPhoneSimulator-9.2-Development
     Build /Users/xxx/.rbenv/versions/2.2.3/lib/ruby/gems/2.2.0/gems/motion-game-1.0/lib/motion-game/../../build/ios
   Compile ./app/scenes/game_over_scene.rb
   Compile ./app/scenes/main_scene.rb
   Compile ./app/scenes.rb
   Compile ./app/scenes/survivor_scene.rb
   Compile ./app/application.rb
    Create build/ios/iPhoneSimulator-9.2-Development/intro_mg.app
      Link build/ios/iPhoneSimulator-9.2-Development/intro_mg.app/intro_mg
    Create build/ios/iPhoneSimulator-9.2-Development/intro_mg.app/PkgInfo
    Create build/ios/iPhoneSimulator-9.2-Development/intro_mg.app/Info.plist
      Copy ./resources/night.wav
      Copy ./resources/survivors
      Copy ./resources/zombie.png
      Copy /Library/RubyMotion/lib/motion/project/template/ios/launch_image/launch_screen.png
      Copy /Library/RubyMotion/lib/motion/project/template/ios/launch_image/launch_screen.storyboardc
    Create build/ios/iPhoneSimulator-9.2-Development/intro_mg.app.dSYM
while processing /Users/xxx/.rbenv/versions/2.2.3/lib/ruby/gems/2.2.0/gems/motion-game-1.0/build/ios/libtiff.a(tif_dirread.o):
warning: no mapping for range.
while processing /Users/xxx/.rbenv/versions/2.2.3/lib/ruby/gems/2.2.0/gems/motion-game-1.0/build/ios/libtiff.a(tif_flush.o):
warning: no mapping for range.
      Copy build/ios/iPhoneSimulator-9.2-Development/intro_mg.app.dSYM
  Simulate build/ios/iPhoneSimulator-9.2-Development/intro_mg.app
*** Starting simulator
iOS Simulator が起動。

 motion-game_zombie1
今度は、人物名をクリックするとゲーム画面に移行しました!

motion-game_zombie2
ゾンビに捕まらないように逃げます。ゾンビもランダムに動きます。

motion-game_zombie3
ゾンビに捕まるとゲームオーバー画面に。
このように動けば動作確認 OKです!


実行中は、やはりエラーが表示されます。
(main)> libpng warning: iCCP: known incorrect sRGB profile
Initializing cpSpace - Chipmunk v6.2.1 (Debug Enabled)
Compile with -DNDEBUG defined to disable debug mode and runtime assertion checks
2016-01-03 12:15:07.692 intro_mg[4776:1591488] Error loading /System/Library/Extensions/IOHIDFamily.kext/Contents/PlugIns/IOHIDLib.plugin/Contents/MacOS/IOHIDLib:  dlopen(/System/Library/Extensions/IOHIDFamily.kext/Contents/PlugIns/IOHIDLib.plugin/Contents/MacOS/IOHIDLib, 262): no suitable image found.  Did find:
/System/Library/Extensions/IOHIDFamily.kext/Contents/PlugIns/IOHIDLib.plugin/Contents/MacOS/IOHIDLib: mach-o, but not built for iOS simulator
2016-01-03 12:15:07.692 intro_mg[4776:1591488] Cannot find function pointer IOHIDLibFactory for factory 13AA9C44-6F1B-11D4-907C-0005028F18D5 in CFBundle/CFPlugIn 0x10e3d6bb0 </System/Library/Extensions/IOHIDFamily.kext/Contents/PlugIns/IOHIDLib.plugin> (bundle, not loaded)
2016-01-03 12:15:07.693 intro_mg[4776:1591488] Error loading /System/Library/Extensions/IOHIDFamily.kext/Contents/PlugIns/IOHIDLib.plugin/Contents/MacOS/IOHIDLib:  dlopen(/System/Library/Extensions/IOHIDFamily.kext/Contents/PlugIns/IOHIDLib.plugin/Contents/MacOS/IOHIDLib, 262): no suitable image found.  Did find:
/System/Library/Extensions/IOHIDFamily.kext/Contents/PlugIns/IOHIDLib.plugin/Contents/MacOS/IOHIDLib: mach-o, but not built for iOS simulator
2016-01-03 12:15:07.693 intro_mg[4776:1591488] Cannot find function pointer IOHIDLibFactory for factory 13AA9C44-6F1B-11D4-907C-0005028F18D5 in CFBundle/CFPlugIn 0x10e3d6bb0 </System/Library/Extensions/IOHIDFamily.kext/Contents/PlugIns/IOHIDLib.plugin> (bundle, not loaded)
2016-01-03 12:15:07.694 intro_mg[4776:1591488] Error loading /System/Library/Extensions/IOHIDFamily.kext/Contents/PlugIns/IOHIDLib.plugin/Contents/MacOS/IOHIDLib:  dlopen(/System/Library/Extensions/IOHIDFamily.kext/Contents/PlugIns/IOHIDLib.plugin/Contents/MacOS/IOHIDLib, 262): no suitable image found.  Did find:
/System/Library/Extensions/IOHIDFamily.kext/Contents/PlugIns/IOHIDLib.plugin/Contents/MacOS/IOHIDLib: mach-o, but not built for iOS simulator
2016-01-03 12:15:07.694 intro_mg[4776:1591488] Cannot find function pointer IOHIDLibFactory for factory 13AA9C44-6F1B-11D4-907C-0005028F18D5 in CFBundle/CFPlugIn 0x10e3d6bb0 </System/Library/Extensions/IOHIDFamily.kext/Contents/PlugIns/IOHIDLib.plugin> (bundle, not loaded)
2016-01-03 12:15:07.695 intro_mg[4776:1591488] Error loading /System/Library/Extensions/IOHIDFamily.kext/Contents/PlugIns/IOHIDLib.plugin/Contents/MacOS/IOHIDLib:  dlopen(/System/Library/Extensions/IOHIDFamily.kext/Contents/PlugIns/IOHIDLib.plugin/Contents/MacOS/IOHIDLib, 262): no suitable image found.  Did find:
/System/Library/Extensions/IOHIDFamily.kext/Contents/PlugIns/IOHIDLib.plugin/Contents/MacOS/IOHIDLib: mach-o, but not built for iOS simulator
2016-01-03 12:15:07.695 intro_mg[4776:1591488] Cannot find function pointer IOHIDLibFactory for factory 13AA9C44-6F1B-11D4-907C-0005028F18D5 in CFBundle/CFPlugIn 0x10e3d6bb0 </System/Library/Extensions/IOHIDFamily.kext/Contents/PlugIns/IOHIDLib.plugin> (bundle, not loaded)
2016-01-03 12:15:07.696 intro_mg[4776:1591488] Error loading /System/Library/Extensions/IOHIDFamily.kext/Contents/PlugIns/IOHIDLib.plugin/Contents/MacOS/IOHIDLib:  dlopen(/System/Library/Extensions/IOHIDFamily.kext/Contents/PlugIns/IOHIDLib.plugin/Contents/MacOS/IOHIDLib, 262): no suitable image found.  Did find:
/System/Library/Extensions/IOHIDFamily.kext/Contents/PlugIns/IOHIDLib.plugin/Contents/MacOS/IOHIDLib: mach-o, but not built for iOS simulator
2016-01-03 12:15:07.696 intro_mg[4776:1591488] Cannot find function pointer IOHIDLibFactory for factory 13AA9C44-6F1B-11D4-907C-0005028F18D5 in CFBundle/CFPlugIn 0x10e3d6bb0 </System/Library/Extensions/IOHIDFamily.kext/Contents/PlugIns/IOHIDLib.plugin> (bundle, not loaded)
exit



補足)チュートリアルがうまく動かなかった場合
上記のようになればいいのですが、最初は色々とつまずきました。
その時の対処法を参考のため、残しておきます。

Xcode 7.2 で、
RubyMotion Starter 4.6 の場合;
$ motion --version
4.6
$ motion create HelloMotion
    Create HelloMotion
    (略)
$ cd HelloMotion
$ rake
  WARNING! The available SDK (9.2) is newer than the latest available RubyMotion BridgeSupport metadata (9.1). The `sdk_version` and `deployment_target` settings will be configured accordingly.
    ERROR! You are using RubyMotion Starter. Only iOS 9.1 is supported in this release. If you would like to target older or newer (in beta) versions of iOS you can purchase a paid subscription.
$ rake
    ERROR! Can't locate iPhoneSimulator SDK 9.1 at `/Applications/Xcode.app/Contents/Developer/Platforms/iPhoneSimulator.platform/Developer/SDKs/iPhoneSimulator9.1.sdk'

RubyMotion Starter 4.6 は iOS 9.1 のみに対応していますが、Xcode 7.2 の iOS Simulator は 9.2 がデフォルトなので、バージョンの食い違いが生じてエラーになってしまいました。


※ Xcode の対応バージョン確認方法
$ xcodebuild -showsdks
OS X SDKs:
OS X 10.11                     -sdk macosx10.11

iOS SDKs:
iOS 9.2                       -sdk iphoneos9.2

iOS Simulator SDKs:
Simulator - iOS 9.2           -sdk iphonesimulator9.2

tvOS SDKs:
tvOS 9.1                       -sdk appletvos9.1

tvOS Simulator SDKs:
Simulator - tvOS 9.1           -sdk appletvsimulator9.1

watchOS SDKs:
watchOS 2.1                   -sdk watchos2.1

watchOS Simulator SDKs:
Simulator - watchOS 2.1       -sdk watchsimulator2.1

つまり Xcode に、
・iOS SDK: iOS 9.1
・iOS Simulator SDK: Simulator - iOS 9.1
が必要となります。

そこで 、Xcode>Preferences>Downloads>Components>iOS 9.1 Simulator
にチェックを入れてインストールしてみましたが、エラーは解消されませんでした。

次に、Xcode の Window>Devices>SIMULATORS
で、左下の「+」を押して「Add Simulator」で適当な iPhone と iOS 9.1 を追加しても、やはりエラーは解消されませんでした。

 
ここで、改めてエラーメッセージを見ると、
Applications/Xcode.app/Contents/Developer/Platforms/iPhoneSimulator.platform/Developer/SDKs フォルダに
iPhoneSimulator9.1.sdk
が必要だと書いてあります。

Xcode.app で右クリックして「パッケージの内容を表示」させると、
上記フォルダには、
・iPhoneSimulator.sdk
・iPhoneSimulator9.2.sdk
の2つしかありません。しかも、iPhoneSimulator9.2.sdk はエイリアスで、右クリックして「情報を見る」と、オリジナルは iPhoneSimulator.sdk でした。

そこで、https://developer.apple.com/downloads/ から旧バージョンの Xcode 7.1.1 をダウンロードして、「パッケージの内容を表示」させて、上記フォルダを開くと、
・iPhoneSimulator.sdk
・iPhoneSimulator9.1.sdk
がありました。 
 iPhoneSimulator9.1.sdk はやはりエイリアスで、オリジナルは iPhoneSimulator.sdk です。この iPhoneSimulator.sdk をコピーして、名前を iPhoneSimulator9.1.sdk にリネームして、上記フォルダに置きました。
つまり、
Applications/Xcode.app/Contents/Developer/Platforms/iPhoneSimulator.platform/Developer/SDKs フォルダには、
・iPhoneSimulator.sdk
・iPhoneSimulator9.1.sdk 
・iPhoneSimulator9.2.sdk(iPhoneSimulator.sdkのエイリアス)
の3つのファイルがあるようにします。

さらに、
$ rake
    ERROR! Can't locate iPhoneOS SDK 9.1 at `/Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS9.1.sdk'
というエラーの対処も同様に、
Xcode 7.1.1 から iPhoneOS9.1.sdk を取ってきて(本体をコピーしてリネームして)、
/Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer/SDKsフォルダに、
置いて、
・iPhoneOS.sdk
・iPhoneOS9.1.sdk
・iPhoneOS9.2.sdk(iPhoneOS.sdkのエイリアス)
の3つのファイルがあるようにします。

これで、
$ rake
     Build ./build/iPhoneSimulator-9.1-Development
   Compile ./app/app_delegate.rb
    Create ./build/iPhoneSimulator-9.1-Development/HelloMotion.app
      Link ./build/iPhoneSimulator-9.1-Development/HelloMotion.app/HelloMotion
    Create ./build/iPhoneSimulator-9.1-Development/HelloMotion.app/PkgInfo
    Create ./build/iPhoneSimulator-9.1-Development/HelloMotion.app/Info.plist
      Copy ./resources/Default-568h@2x.png
      Copy ./resources/Default-667h@2x.png
      Copy ./resources/Default-736h@3x.png
      Copy /Library/RubyMotion/lib/motion/project/template/ios/launch_image/launch_screen.png
      Copy /Library/RubyMotion/lib/motion/project/template/ios/launch_image/launch_screen.storyboardc
    Create ./build/iPhoneSimulator-9.1-Development/HelloMotion.app.dSYM
      Copy ./build/iPhoneSimulator-9.1-Development/HelloMotion.app.dSYM
  Simulate ./build/iPhoneSimulator-9.1-Development/HelloMotion.app
*** Starting simulator
無事チュートリアルが起動するようになりました。

※ 修正後のXcode の対応バージョン確認
$ xcodebuild -showsdks
OS X SDKs:
OS X 10.11                     -sdk macosx10.11

iOS SDKs:
iOS 9.1                       -sdk iphoneos9.1
iOS 9.2                       -sdk iphoneos9.2

iOS Simulator SDKs:
Simulator - iOS 9.1           -sdk iphonesimulator9.1
Simulator - iOS 9.2           -sdk iphonesimulator9.2

tvOS SDKs:
tvOS 9.1                       -sdk appletvos9.1

tvOS Simulator SDKs:
Simulator - tvOS 9.1           -sdk appletvsimulator9.1

watchOS SDKs:
watchOS 2.1                   -sdk watchos2.1

watchOS Simulator SDKs:
Simulator - watchOS 2.1       -sdk watchsimulator2.1

ちなみに、
Rakefile に
app.sdk_version = '9.1'
app.deployment_target = '9.1'
という指定を追加する
という情報も見かけましたが、RubyMotion Starter は iOS のバージョンは決め打ちされているので、やっても無駄でした。
 

以上、RubyMotion と Xcode のバージョンが上がった時に、またこのようなエラーが出る可能性があるので、その時は参考にしてください。





RubyMotion (The Pragmatic Programmers)
Clay Allsopp
Pragmatic Bookshelf
2013-01-09



RubyMotion iOS Develoment Essentials
Abhishek Nalwaya
Packt Publishing
2013-07-16



Instant RubyMotion App Development
Gant Laborde
Packt Publishing
2013-07-25