Cocos2d で CCUIViewWrapper を使用することと、移植された機能を使用することの長所と短所を理解しようとしています。たとえば、CCUIViewWrapper で UITableView を使用するか、CCTableViewSuite を使用する方がよいでしょうか。一見すると、おそらくUITableViewが提供するすべてのことを実行できるため、ラッパーの方が優れたアプローチであると思いますが、欠けている重要な詳細はありますか? Apple SDK オブジェクトを実際に使用したり、CCTableView などの移植されたオブジェクトに付属する Cocos2d 内の特定の機能を利用できないなど、ラッパーに深刻な制限がありますか?
2 に答える
あなたの質問に答えるのに役立つかもしれないこの投稿をここからコピーしました。cocos2d関数をcocos2dラッパーで使用する方が良いと思いますが、他のものと実装することもできますが、統合されません.
UIKit アイテムを cocos2d と統合する方法について追加のヘルプが必要な初心者 (私のような) がいる場合、これが役立つ可能性があります。このスレッドの最初の投稿で読んだように、Blue Ether は UIView を操作するためのラッパーを作成しました。UIView とは何ですか? http://developer.apple.com/iphone/library/documentation/uikit/reference/uikit_framework/Introduction/Introduction.htmlを見て、少し下にスクロールすると、さまざまな UIView 項目の図が表示されます。UIButton、UISlider、UITextView、UILabel、UIAlertView、UITableView、UIWindow など。それらの数は20以上あります。Blue Ethas コードを使用して、それらのいずれかを cocos2d 内にラップできます。ここでは UIButton をラップしますが、UIView 項目のお気に入りの選択を試してください。
新しい cocos 2d アプリケーション プロジェクトを作成します。
新しい NSObject ファイルを作成し、CCUIViewWrapper という名前を付けます。これにより、ファイル CCUIViewWrapper.h と CCUIViewWrapper.m が得られます。Blue Ether が定義したように見えるように (コピー ペーストで) 編集します (このスレッドの最初の投稿を参照してください。
HelloWorld.h を次のようにします。
// HelloWorldLayer.h #import "cocos2d.h" #import <UIKit/UIKit.h> #import "CCUIViewWrapper.h" @interface HelloWorld : CCLayer { UIButton *button; CCUIViewWrapper *wrapper; } +(id) scene; @end
そしてあなたの HelloWorld.m はこのように
// HelloWorldLayer.m
#import "HelloWorldScene.h"
// HelloWorld implementation
@implementation HelloWorld
+(id) scene
{
CCScene *scene = [CCScene node];
HelloWorld *layer = [HelloWorld node];
[scene addChild: layer];
return scene;
}
-(void)buttonTapped:(id)sender
{
NSLog(@"buttonTapped");
}
// create and initialize a UIView item with the wrapper
-(void)addUIViewItem
{
// create item programatically
button = [UIButton buttonWithType:UIButtonTypeRoundedRect];
[button addTarget:self action:@selector(buttonTapped:) forControlEvents:UIControlEventTouchDown];
[button setTitle:@"Touch Me" forState:UIControlStateNormal];
button.frame = CGRectMake(0.0, 0.0, 120.0, 40.0);
// put a wrappar around it
wrapper = [CCUIViewWrapper wrapperForUIView:button];
[self addChild:wrapper];
}
-(id) init
{
if( (self=[super init] )) {
[self addUIViewItem];
// x=160=100+120/2, y=240=260-40/2
wrapper.position = ccp(100,260);
[wrapper runAction:[CCRotateTo actionWithDuration:4.5 angle:180]];
}
return self;
}
- (void) dealloc
{
[self removeChild:wrapper cleanup:true];
wrapper = nil;
[button release];
button=nil;
[super dealloc];
}
@end
ビルドして実行します。これにより、シーンの中央に回転ボタンが生成されます。回転中はボタンをタッチできます。コンソールにテキスト メッセージが書き込まれます。
CCUIViewWrapper は適切なソリューションではありません。私はそれを試して削除しました。問題は、UIKit 要素をコンテナーにラップし、それをディレクターのビューとして openGL メイン ビューに追加することです。これに関する 1 つの問題は、その上に他のスプライトを追加できないことです。非常に限られています。