Seasons.NET

ちょっとした技術ブログです

cocos2d 0.99.5 templateに追加された2種類のオートローテート

元記事

cocos2dとUIKitを混合させる上で割と面倒なのが、
画面の回転です。


今までは、cocos2dにおいて画面回転を行うロジックに
glRotateを用いてました。
これは、GLESの画面は回転しても、EAGLViewそのものは
回転していませんでした。


つまり、UIKitのViewをaddSubViewした時に自前で
回転させる必要があったのです。


これを解消するためにcocos2d 0.99.5ではソースコード
いくつかアップデートが施されています。

以下本文抜粋

In order to be iPad compliant, v0.99.5 will include updated templates that support autorotation.
画面の回転用にv0.99.5では自動回転をサポートするテンプレートを組み込む予定である。

Basically the new templates will have 3 new files:
3つのファイルが追加される。
    * GameConfig.h
    * RootViewController.m (and .h)

The RootViewController.* files contain the code to handle the autorotation.
RooViewControllerは、自動回転を制御する。

And in GameConfig.h you will be able to configure how to handle the autorotation:
GameConfig.hでは自動回転に関する設定を行う。

    * No autorotation
   全く回転しない。
    * Autorotation handled by cocos2d
   cocos2d側で回転させる。
    * Autorotation handled by UIViewController (default)
   UIViewController側で回転させる(デフォルト)

No Autorotation: It means just that. The EAGLView won’t be autorotated
No Autoratation=回転しない とはEAGLViewが回転しないことを示す。

Autorotation by cocos2d: The EAGLView will be “rotated” using CCDirector#setDeviceOrientation.
cocos2d側で回転するということは、CCDirector:setDeviceOrientationを利用することである。

    * [+]: It is the fatest way to “rotate” the EAGLView since it uses one glRotatef() command (technically the EAGLView is not rotated).
    * [-]: If you are going to add UIKit objects to the EAGLView, then you will need to rotate them manually.

これは、glRotatefを使って回転するが、UIKitのオブジェクトを追加するときはユーザーの手で回転コードを記述する必要がある。

Autorotation by UIViewController: The EAGLView will be rotated by the UIViewController
UIViewControllerを使って回転させることは、EAGLViewがUIViewControllerによって回転させられることである。

    * [-]: The UIViewController will rotate the EAGLView and it is bit slower than using a single glRotate() command.
    * [+]: There is no need to rotate any UIKit object contained by the EAGLView.
UIViewControllerの回転は、glRotateに比べると少し遅いが、UIKitオブジェクトを追加した際に回転コードを記述する必要がない。