7

我正在尝试使用 Cocos2d 构建一个 iPhone 应用程序。但我使用了四种类型的类,如下所示-

@interface MenuScene : Scene {}

@end
@interface FlipView : UIImageView
{
    CGPoint startTouchPosition;
    NSString *dirString;
    UIImageView *firstPieceView;   
    UIImageView *secondPieceView;

}
@end

@interface HelloController : UIViewController
@end


@interface MenuLayer: Layer{
        Todo *todo;
        Menu * menu;
        sqlite3 *database;
        NSMutableArray *todos;
    NSString *dirString;
    CGPoint startTouchPosition;
}
@property (nonatomic, retain) NSMutableArray *todos;
-(void) button1: (id)sender;
-(void) button2: (id)sender;
-(void) black_jack: (id)sender;
@end

但是如何通过 MenuLayer 类显示 FlipView 和 HelloController 类。

4

2 回答 2

20

If you are asking how to attach UIKit views and such to a cocos2d-iphone project, you just have to do it like:

[[[Director sharedDirector] window] addSubview:myView];

Updated to cocos 0.7 and now this is:

[[[Director sharedDirector] openGLView] addSubview:myView];

And in Cocos 0.99:

[[[CCDirector sharedDirector] openGLView] addSubview:myView];

And in Cocos 2.0

[[[CCDirector sharedDirector] view] addSubview:myView];
于 2009-02-10T01:18:31.657 回答
2

It's very difficult to answer this question just from the code but I think you need to go back and read up a little on UIKit design and cocos2d programming.

HelloController is a view controller - you cannot 'show' it. A view controller is a class that replies to messages from a view and controls the data it displays from the model.

FlipView is an ImageView which is a subclas of UIView. To have UIKit render this image, you need to add it to another view using [UIView addSubView:...]

Here's what I think you want to do:

  1. The menu item receives a touch event. It signals to:
  2. the view controller which
  3. adds the UIImage to the main view

Like I said though, this is a very general question and I really think you should go back to the documentation and think about your design. The Apple docs are good and there are some good iPhone books on the market now.

于 2009-02-10T01:04:54.293 回答