Cocos2d ユーザの面倒だったところに手が届く、Kobold2d の親切設計

Kobold2D ちょっと使ってみました。障りだけですが、よく設計されているのがわかります。
良いなと思った事を記述します。

  1. AppDelegate, RootViewControllerがシンプル
  2. cocos2d を使っていると、AppDelegate が非常に複雑になってしまいます。また、標準でかなり長いAppDelegateに、自分のコードを追加するので、バージョンアップのときのマージが大変です。それが、Kobold2dの場合は、cocos2d関係のコードがすべて KKAppDelegate にまとめられていて、各アプリでは、そのアプリに関係する事だけ書けばいいようになっているので、バージョンアップも楽そうです。
    こんな感じです。
    AppDelegate.h
    [cc lang=”ObjC”]
    /*
    * Kobold2D™ — http://www.kobold2d.org
    *
    * Copyright (c) 2010-2011 Steffen Itterheim.
    * Released under MIT License in Germany (LICENSE-Kobold2D.txt).
    */

    #import “KKAppDelegate.h”

    @interface AppDelegate : KKAppDelegate
    {
    }
    @end
    [/cc]
    AppDelegate.m
    [cc lang=”ObjC”]
    /*
    * Kobold2D™ — http://www.kobold2d.org
    *
    * Copyright (c) 2010-2011 Steffen Itterheim.
    * Released under MIT License in Germany (LICENSE-Kobold2D.txt).
    */

    #import “AppDelegate.h”

    @implementation AppDelegate

    // Note: only override the UI/NSApplicationDelegate methods that you absolutely must handle yourself.
    // In most cases you will still want to call the [super ..] implementation,
    // unless you want to override the KKAppDelegate behavior entirely.

    // Called when Cocos2D is fully setup and you are able to run the first scene
    -(void) initializationComplete
    {
    // If iAd is enabled and you want to supply your own AdBannerViewDelegate, use this code:
    //[[KKAdBanner sharedAdBanner].adBannerView setDelegate:yourAdBannerViewDelegate];

    // Note: if you specify FirstSceneClassName in startup-config.lua you do not need to call runWithScene at all!
    // If you have to, you can still call runWithScene here, for example to add some logic to select one of many scenes to run first
    //[[CCDirector sharedDirector] runWithScene:[test test]];
    }

    @end
    [/cc]
    RootViewController.m
    [cc lang=”ObjC”]
    /*
    * Kobold2D™ — http://www.kobold2d.org
    *
    * Copyright (c) 2010-2011 Steffen Itterheim.
    * Released under MIT License in Germany (LICENSE-Kobold2D.txt).
    */

    #import “RootViewController.h”

    #ifdef KK_PLATFORM_IOS

    @implementation RootViewController

    // Note: only override the UIViewController methods that you absolutely must handle yourself.
    // In most cases you will still want to call the [super ..] implementation,
    // unless you want to override the KKRootViewController behavior entirely.

    @end

    #endif
    [/cc]

  3. Config.luaでいろんなことが出来る
  4. [cc lang=”ObjC”]
    –[[
    * Kobold2D™ — http://www.kobold2d.org
    *
    * Copyright (c) 2010-2011 Steffen Itterheim.
    * Released under MIT License in Germany (LICENSE-Kobold2D.txt).
    –]]

    –[[
    * Need help with the KKStartupConfig settings?
    * —— http://www.kobold2d.com/x/ygMO ——
    –]]

    local config =
    {
    KKStartupConfig =
    {
    — load first scene from a class with this name, or from a Lua script with this name with .lua appended
    FirstSceneClassName = “ZKOpeningLayer”,

    — set the director type, and the fallback in case the first isn’t available
    DirectorType = DirectorType.DisplayLink,
    DirectorTypeFallback = DirectorType.NSTimer,

    MaxFrameRate = 60,
    DisplayFPS = YES,

    EnableUserInteraction = YES,
    EnableMultiTouch = NO,

    — Render settings
    DefaultTexturePixelFormat = TexturePixelFormat.RGBA8888,
    GLViewColorFormat = GLViewColorFormat.RGB565,
    GLViewDepthFormat = GLViewDepthFormat.DepthNone,
    GLViewMultiSampling = NO,
    GLViewNumberOfSamples = 0,

    Enable2DProjection = NO,
    EnableRetinaDisplaySupport = NO, — there are no Retina assets in this template project

    — Orientation & Autorotation
    DeviceOrientation = DeviceOrientation.LandscapeLeft,
    AutorotationType = Autorotation.UIViewController,
    ShouldAutorotateToLandscapeOrientations = YES,
    ShouldAutorotateToPortraitOrientations = NO,
    AllowAutorotateOnFirstAndSecondGenerationDevices = YES,

    — iAd setup
    — Note: for iAd to support autorotation you should use: AutorotationType = Autorotation.kAutorotationUIViewController
    EnableAdBanner = YES,
    LoadOnlyPortraitBanners = NO,
    LoadOnlyLandscapeBanners = YES,
    PlaceBannerOnBottom = YES,

    — Mac OS specific settings
    AutoScale = NO,
    AcceptsMouseMovedEvents = NO,
    WindowFrame = RectMake(1024-640, 768-480, 640, 480),
    },

    — you can create your own config sections using the same mechanism and use KKConfig to access the parameters
    — or use the KKConfig injectPropertiesFromKeyPath method
    MySettings =
    {
    },
    }

    return config
    [/cc]
    これが、設定ファイルで、これを編集することによって、いろんな事が出来ます。
    例えば

    1. 初期レイヤーの設定
    2. マルチタッチの有無
    3. 回転方法のメソッド
    4. Retinaを使用するか
    5. iAdを使用するか (次のバージョンでAdMobも設定可能)

    などです、これらを、コードではなくて、設定ファイルで設定出来るのは嬉しいですね。

アプリのサイズも、サンプルコードからそのままipaファイルを作ってみたところ、700キロバイト大だったので、たくさんのライブラリをリンクしていますが、サイズにはあまり影響がないようでした。ちょっとこれを触っていろいろ作ってみたいと思います。

コメントを残す

メールアドレスが公開されることはありません。 が付いている欄は必須項目です

このサイトはスパムを低減するために Akismet を使っています。コメントデータの処理方法の詳細はこちらをご覧ください