Cocoapodsに依ってライブラリPhysicsDebuggerを使う(前編)

SpriteKitフレームワークの物理エンジンで生成される物理体は ゲーム上のキャラクターなどを単純な形で包括して衝突判定などに活かされます。 ゲーム画面で見えてはならない此の物理体もゲーム開発中には想定通りの状態を保持しているか 把握のために可視化したくあります。 此の状況に有用なライブラリとして PhysicsDebugger が紹介されていましたので利用を目論むのでしたが さてライブラリを導入するとなると依存関係が気になります。 其の様な煩わしいライブラリ間の依存の管理は CocoaPods に頼るべしとて多くの情報が流通していましたので流れに身を任せた次第。

PhysicsDebuggerに依る剛体表示

先ずCocoapodsのインストールですが 然うは問屋が卸さずとばかりにターミナルを用いた処理は途中で停止して一向に進みません。 Qiitaに2013年10月13日に配信される CocoaPodsがインストール出来ない時 などに依れば RubyGems をアップデートすべしとありますので従って後無事再インストールの首尾良く運んだのでしたが どうにも先が思いやられる感も有ったりしつつ@ITの2014年3月10日の記事 生産性ガチアゲなオープンソースiOSライブラリ(終):iOSライブラリ管理の神ツール「CocoaPods」のインストールと使い方 (1/2) を参考にターミナルから ~/.cocoapods ディレクトリを作成、場所の確認などもして先に進みます。

- Last login: Sun Apr 6 20:34:16 on console
$ pod setup
Setting up CocoaPods master repo
Setup completed (read-only access)
$ sudo find / -name "*cocoa*"
スポンサーリンク
日付:2014年4月10日
開発機:MacBook Air(11-inch, Mid 2013)
MacOSバージョン:OS X 10.9.2
Xcodeバージョン:5.1
言語:Objective-C
主関連アプリ:uPanda Breaks Out Fruits

RubyGem、Cocoapodsと適正な導入のなりましたので漸くライブラリ PhysicsDebugger の導入の段となります。 ソースはGitHubで提供されています。

PhysicsDebugger/PhysicsDebugger at master · ymc-thzi/PhysicsDebugger

以下がライブラリ使用のための作成Podfileの内容です。

  • ディレクトリ:/Documents/iPhoneAppli/uPanda\ Breaks\ Out\ Fruits
  • ファイル名:Podfile
  • ファイル内容:pod 'PhysicsDebugger', git: 'https://github.com/ymc-thzi/PhysicsDebugger.git'

然る後のターミナル操作が以下です。

$ cd /Documents/iPhoneAppli/uPanda\ Breaks\ Out\ Fruits
$ pod install
Analyzing dependencies
Pre-downloading: `PhysicsDebugger` from `https://github.com/ymc-thzi/PhysicsDebugger.git`
Downloading dependencies
Installing PhysicsDebugger (1.0.2)
Generating Pods project
Integrating client project

[!] From now on use `uPanda Breaks Out Fruits.xcworkspace`.

[!] The target `uPanda Breaks Out Fruits [Debug]` overrides the `OTHER_LDFLAGS` build setting defined in `Pods/Pods.xcconfig'.
  - Use the `$(inherited)` flag, or
  - Remove the build settings from the target.

[!] The target `uPanda Breaks Out Fruits [Debug - Release]` overrides the `OTHER_LDFLAGS` build setting defined in `Pods/Pods.xcconfig'.
  - Use the `$(inherited)` flag, or
  - Remove the build settings from the target.

しかし此れではプロジェクトからライブラリが読み込めないので Podfileのファイル内容を書き換えて再びインストールします。

  • platform :ios, "6.0"
  • pod 'AFNetworking', '~> 2.0'
  • pod 'PhysicsDebugger', git: 'https://github.com/ymc-thzi/PhysicsDebugger.git'
$ pod install
Analyzing dependencies
[!] The platform of the target `Pods` (iOS 6.0) is not compatible with `PhysicsDebugger (1.0.2)` which has a minimum requirement of iOS 7.0.

iOS7以上を必要とするとの警告でインストールが不能となりますが 考えてみればSpritekitなので当然と言えば当然です。 再び以下の様にPodfileの内容を書き換えます。

  • platform :ios, "7.0"
  • pod 'AFNetworking', '~> 2.0'
  • pod 'PhysicsDebugger', git: 'https://github.com/ymc-thzi/PhysicsDebugger.git'
$ pod install
Analyzing dependencies
Downloading dependencies
Installing AFNetworking (2.2.1)
Using PhysicsDebugger (1.0.2)
Generating Pods project
Integrating client project

どうやら上手くインストール出来た様ですので 稼働を確認するためXcodeからプロジェクトを開きますが此の際 uPanda Breaks Out Fruits.xcworkspace を開きます。 uPanda Breaks Out Fruits.xcodeproj は元のプロジェクトでPodsライブラリがリンクされていません。 開いたら PlayScene.m を編集し #import "YMCPhysicsDebugger.h" を書き加えメソッド -(id)initWithSize:(CGSize)size life:(int)life stage:(int)stage score:(int)score に以下で緑字部分を書き加えます。

-(id)initWithSize:(CGSize)size life:(int)life stage:(int)stage score:(int)score
{
  self = [super initWithSize:size];
  if (self) {
    [YMCPhysicsDebugger init];
    /* Create scene contens */
    [self drawPhysicsBodies];
  }
  return self;
}

ビルドすればエラーは出ませんので一応機能はしている様ですが 実際にプログラムを走らせても PhysicsDebugger を以て描画されるべき赤枠が表示されませんので恐らく pod 'AFNetworking', '~> 2.0' は関係ないのではないかと思い Podfileのファイル内容を以下の如く書き換えてアップデートしてみます。

  • platform :ios, "7.0"
  • pod 'PhysicsDebugger', git: 'https://github.com/ymc-thzi/PhysicsDebugger.git'
$ pod update
Analyzing dependencies
Pre-downloading: `PhysicsDebugger` from `https://github.com/ymc-thzi/PhysicsDebugger.git`
Removing AFNetworking
Downloading dependencies
Installing PhysicsDebugger (1.0.2)
Generating Pods project
Integrating client project

アップデート自体は問題有りませんが矢張り期待される赤枠は表示されませんので 何某か未だ解決されざる問題がある様です。 記事が長くなりましたので此の解決は後編の稿に譲ります。